pandoc/dockerfiles

Roboto.sty is installed, but not found when run in CI-pipeline

StefanSchroeder opened this issue · 14 comments

I am using the image: pandoc/latex:latest-ubuntu.
Since I want to use the Roboto-font, I am adding the command "apt install -y texlive-fonts-extra" in my .gitlab-ci.yml.
(The roboto-font is part of this compilation as indicated here: https://packages.debian.org/sid/texlive-fonts-extra)
The sty-file is properly installed:
ls /usr/share/texlive/texmf-dist/tex/latex/roboto/roboto.sty
succeeds.
Yet, when I use this preamble in my markdown file with pandoc:

output: pdf_document
fontfamily: roboto

this error occurs:

Error producing PDF.
! LaTeX Error: File `roboto.sty' not found.
Type X to quit or to proceed,
or enter new name. (Default extension: sty)
[...]
l.10 \usepackage

Can somebody point out, what it missing here or why the installed sty-file is not found?

Thanks

I suggest to use tlmgr as install directory differs between apt and tlmgr

TL;DR

tlmgr install roboto fontaxes clears error around roboto

Details

I am also not a latex expert but tried to reproduce your condition

Run docker image. change entrypoint to sh this time
$ docker run -it --rm --entrypoint "sh" pandoc/latex:latest-ubuntu

update apt database and install package
$ sudo apt update; sudo apt install -y texlive-fonts-extra
This does mktexlsr in middle of installation so font should be visible from latex but mktexlsr searches different places.

Note: here pandoc command causes the error about roboto.sty as you mentioned
$ pandoc -tpdf -Mfontfamily=roboto markdown.md -o pdf.pdf

$ ls /usr/share/texlive/texmf-dist/tex/latex/roboto/roboto.sty
/usr/share/texlive/texmf-dist/tex/latex/roboto/roboto.sty

$ mktexlsr
mktexlsr: Updating /opt/texlive/texdir/texmf-config/ls-R... 
mktexlsr: Updating /opt/texlive/texdir/texmf-dist/ls-R... 
mktexlsr: Updating /opt/texlive/texdir/texmf-var/ls-R... 
mktexlsr: Updating /opt/texlive/texmf-local/ls-R... 
mktexlsr: Done.

I see this mismatch is the cause of your problem. Now I tried to install roboto via tlmgr
# tlmgr install roboto

then I could find the sty under one of the search directory

$ cat /opt/texlive/texdir/texmf-dist/ls-R |grep roboto
roboto
./fonts/enc/dvips/roboto:
roboto
./fonts/map/dvips/roboto:
roboto.map
roboto
./fonts/opentype/google/roboto:
roboto
./fonts/tfm/google/roboto:
roboto
./fonts/type1/google/roboto:
roboto
./fonts/vf/google/roboto:
roboto
./tex/latex/roboto:
roboto-mono.sty
roboto-serif.sty
roboto.sty

now run pandoc again
$ pandoc -tpdf -Mfontfamily=roboto markdown.md -o pdf.pdf
this caused another error about fontaxes.sty, which suggests no more problem with roboto.sty

tlmgr install fontaxes and rerun the same pandoc command. no error. 👍

finally, input file:
$ cat markdown.md

# header

text

## another header

another text
jgm commented

you probably want

mainfont: Roboto
pdf-engine: xelatex

because fontfamily is for pdflatex and tex sty files, not ttf fonts.

(I found it was better to use bash instead of sh for docker run)

Well, roboto is available as ttf as well as latex-sty package. That being said, it should be possible to access the roboto-font family from pdflatex as well as xelatex.

@K4zuki When I follow exactly your procedure, I am getting this error:

Error producing PDF.
! pdfTeX error (font expansion): auto expansion is only possible with scalable
fonts.
...shipout:D \box_use:N \l_shipout_box
_shipout_drop_firstpage...
l.170 \end{longtable}

I am somewhat confused about the use of tlmgr here. Isn't the tlmgr installation in conflict with the installation of the ubuntu/debian packages installed with apt? I have the suspicion that by installing texlive-fonts-extra I am pulling in the ubuntu-texlive distribution which in turn breaks the tlmgr installation.

When switching to xelatex as suggested by John -- strangely enough -- the document is generated properly without error, but the roboto-font is not applied!

Now this is my header (in a separate file pandoc-pre-yml):


geometry: "left=25mm,right=25mm,top=10mm,bottom=25mm"
mainfont: Roboto
pdf-engine: xelatex
toc: true

This is my call to pandoc:

- tlmgr update --self && tlmgr install roboto fontaxes
- pandoc --metadata-file=pandoc-pre.yml README.md -o output/README.pdf

This code produces a PDF with LMRoman font.

Can you perhaps point to a sample project somewhere, where the roboto font is applied?

I now have been able to tweak the project to use the Roboto font as desired. I am capturing the solution here for reference and will then close the issue:

This is the file: pandoc-pre.yml

geometry: "left=25mm,right=25mm,top=10mm,bottom=25mm"
mainfont: Roboto
pdf-engine: xelatex
toc: true

This is the relevant section of .gitlab-ci.yml

build:
  script:
    - apt update && DEBIAN_FRONTEND=noninteractive apt install -y fonts-roboto fonts-dejavu
    - tlmgr update --self && tlmgr install roboto fontaxes dejavu
    - mkdir output
    - pandoc README.md --pdf-engine=xelatex --metadata-file=pandoc-pre.yml -o output/README.pdf
  artifacts:
    paths:
      - "output"

This solution is not minimal. The Dejavu-font could be removed here.
Also, it's still to be examined which of the calls - apt or tlmgr - is actually required.
Also, only 1 definition of pdf-engine should suffice.

Thank you to Yamamoto-san and John for helping.

The call to tlmgr could be skipped: the mainfont setting only takes effect when pandoc is called with xelatex as PDF engine, and XeLaTeX searches the system's fonts, which are controlled through apt.

Pandoc makes a distinction between metadata and conversion parameters. The former are part of the document's YAML block or passed via --metadata-file, but only the latter can control which PDF engine is used. See the pandoc manual on "defaults files". That's why setting pdf-engine in the metadata has no effect in the code above.

huh, that's surprising as it was suggested by jgm above. 🤸‍♀️

thank you for the improvement suggestions, @tarleb . that's great advice and saves me a lot of time optimizing.

For completeness, this also works:

tlmgr install roboto
pandoc -o out.pdf in.md --pdf-engine=xelatex -V fontfamily=roboto

Using lualatex as the pdf-engine works as well. It seems that pdflatex just doesn't work with that package.

didn't you say earlier that xelatex/lualatex use the system-fonts and should therefore not have any need for tlmgr?

I agree, that's terribly confusing, isn't it? I was confused myself for a second (and partly wrong / imprecise in my comment above).

The difference in the above commands is fontfamily vs. mainfont: using fontfamily causes pandoc to load the font via a \usepackage, whereas mainfont causes a call to LaTeX's \setmainfont. I'm no LaTeX fonts expert, but I believe that only LuaLaTeX and XeLaTeX understand \setmainfont, while all LaTeX engines can use the \usepackage{roboto}.

Danke.