Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX compilation fails with libertinus font package #10655

Closed
jchiquet opened this issue Aug 30, 2024 · 11 comments · Fixed by #10684
Closed

LaTeX compilation fails with libertinus font package #10655

jchiquet opened this issue Aug 30, 2024 · 11 comments · Fixed by #10684
Assignees
Labels
bug Something isn't working latex LaTeX engines related libraries and technologies
Milestone

Comments

@jchiquet
Copy link

jchiquet commented Aug 30, 2024

Bug description

When rendering PDF documents and setting the fontfamilyoptions as exemplified on the Quarto website, fontspec cannot find the appropriate font file, even though tlmgr appears to install it on the fly. This issue causes the rendering to fail when using either XeTeX or LuaLaTeX.

A possible fix is to manually install and register the font with TinyTeX before rendering: ~/.TinyTeX/bin/x86_64-linux/tlmgr install libertinus-fonts.

Although this seems more like a tlmgr/TinyTeX bug, I believe it's important to mention this issue here since it relates to an example taken directly from the Quarto documentation.

Steps to reproduce

Here is a minimal qmd file to reproduce :

---
title: "Quarto and libertinus"
format:
    pdf:
      fontfamily: libertinus
      fontfamilyoptions:
        - osf
        - p  
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

I have also set up a gh repo for reproducibility, see the failing actions there :
https://github.com/jchiquet/quarto-libertinus/actions/runs/10631297158/job/29471892228

Expected behavior

No response

Actual behavior

Rendering PDF
running lualatex - 1
  This is LuaHBTeX, Version 1.18.0 (TeX Live 2024) 
   restricted system commands enabled.
  
  luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: File not found: "LibertinusSerif-Regular.otf".
updating tlmgr

updating existing packages
ERROR: 
compilation failed- error
Package fontspec Error: 
(fontspec)                The font "LibertinusSerif-Regular" cannot be
(fontspec)                found; this may be but usually is not a fontspec
(fontspec)                bug. Either there is a typo in the font name/file,
(fontspec)                the font is not installed (correctly), or there is
(fontspec)                a bug in the underlying font loading engine
(fontspec)                (XeTeX/luaotfload).

For immediate help type H <return>.
 ...                                              
                                                  
l.232 ]

Your environment

No response

Quarto check output

Quarto 1.5.56
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.56
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.07.03
      Chromium: 869685

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/jchiquet/.TinyTeX/bin/x86_64-linux
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.12
      Path: /usr/bin/python3
      Jupyter: 5.2.0
      Kernels: python3, julia-1.8

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /usr/lib/R
      LibPaths:
        - /home/jchiquet/Repos/computo/quarto-libertinus/renv/library/linux-ubuntu-jammy/R-4.4/x86_64-pc-linux-gnu
        - /home/jchiquet/.cache/R/renv/sandbox/linux-ubuntu-jammy/R-4.4/x86_64-pc-linux-gnu/9a444a72
      knitr: 1.48
      rmarkdown: 2.28

[✓] Checking Knitr engine render......OK
@jchiquet jchiquet added the bug Something isn't working label Aug 30, 2024
@jchiquet jchiquet changed the title LaTeX compilation fails when fontfamilyoptions is tuned as in the quarto documentions LaTeX compilation fails when fontfamilyoptions is tuned as in the quarto documention Aug 30, 2024
@mcanouil
Copy link
Collaborator

mcanouil commented Sep 1, 2024

The issue is not Quarto but your setup or use of TinyTex (https://github.com/rstudio/tinytex) as indicated in the log File not found: "LibertinusSerif-Regular.otf".

I don't believe TinyTex automatically install fonts, but I might be wrong.
CC @cderv

InputOutput
---
title: "Quarto and libertinus"
format:
  pdf:
    fontfamily: merriweather
    fontfamilyoptions:
      - sfdefault
---

## Quarto

Quarto enables you to weave together content and
executable code into a finished document.
To learn more about Quarto see <https://quarto.org>.
image

@mcanouil mcanouil added the latex LaTeX engines related libraries and technologies label Sep 1, 2024
@jchiquet
Copy link
Author

jchiquet commented Sep 2, 2024

Thank @mcanouil .

I can run your example smoothly with the merriweather font on my computer (on which, indeed, Tiny Tex is installing the missing font package automatically) :

Rendering PDF
running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
  
updating tlmgr

updating existing packages
finding package for merriweather.sty
> 1 package to install
> installing merriweather (1 of 1)
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
  
running xelatex - 2
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
  

Output created: test.pdf

The same code fails with Libertinus, as I said earlier, cause of the supposedly missing file LibertnusSerif-Regular.otf . However, calling manually TinyTex solves the issues.

~/.TinyTeX/bin/x86_64-linux/tlmgr install libertinus-fonts 

So I'm going to try my luck by reporting the bug on the TinyTex repo.

@cderv
Copy link
Collaborator

cderv commented Sep 2, 2024

I'll look into this.

Just to be clear: TinyTeX, the distribution is not responsible for automatic package installation. It seems here this is an issue of the right missing package to be installed. It is possible that the wrong package is installed, or something else specific if not taken into account.

In R ecosystem for R Markdown, tinytex the R package is the one doing the log parsing, and detecting which package to install, and running the install command.

In Quarto, this is internal Quarto LaTeX engine which does this.

I'll follow this trail and find more. From what I can observe trying to reproduce, Quarto correctly tries to install packages, but not the one you mentioned called libertinus-fonts. It is trying libertinus-otf, and somehow not finding the font afterward.

updating existing packages
finding package for libertinus.sty
> 1 package to install
> installing libertinus (1 of 1)
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
  
finding package for libertinus-otf.sty
> 1 package to install
> installing libertinus-otf (1 of 1)
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

ERROR: 
compilation failed- error
Package fontspec Error: 
(fontspec)                The font "LibertinusSerif-Regular" cannot be
(fontspec)                found; this may be but usually is not a fontspec
(fontspec)                bug. Either there is a typo in the font name/file,
(fontspec)                the font is not installed (correctly), or there is
(fontspec)                a bug in the underlying font loading engine
(fontspec)                (XeTeX/luaotfload).

@cderv cderv self-assigned this Sep 2, 2024
@cderv cderv added this to the v1.6 milestone Sep 2, 2024
@mcanouil
Copy link
Collaborator

mcanouil commented Sep 2, 2024

Thanks @cderv for the insight!

@cderv
Copy link
Collaborator

cderv commented Sep 2, 2024

Problem is the same with R Markdown. So not a Quarto problem directly.

When no package installed, first render gives in the log a missing libertinus.sty, so Quarto and tinytex both install libertinus. Second render still with xelatex, libertinus-otf.sty is now found and install.

It seems this is not enough to render the pdf.

When we do install libertinus-fonts before rendering, and I redo the above step with none of the two packages installed. Then, they will still be needed and they will still be installed, but now the font is found and the rendering completes. So it seems the 3 packages are needed 🤔

Usually, when a font is missing, it is logged by LaTeX in missfont.log. But for this rendering, it is never reported. So maybe that is why it is not automatically installed, and detected ?

libertinus-fonts seems the key to this. We may need a specific install for this package.

This is quite specific to libertinus. @jchiquet I can reproduce a build error without any fontfamilyoptions, so I am not sure why your issue title specifically mention this. It seems to me this is a specific LaTeX problem with libertinus font packages.

@jchiquet jchiquet changed the title LaTeX compilation fails when fontfamilyoptions is tuned as in the quarto documention LaTeX compilation fails with libertinus font package Sep 2, 2024
@cderv
Copy link
Collaborator

cderv commented Sep 2, 2024

Let's not that libertinus and libertinus-otf does not contains any fonts ! I mean no .otf file. So this is probably why it is not working. Those packages are not enough to use the font.

The font is included only in libertinus-fonts package

> tinytex::tlmgr_search("LibertinusSerif-Regular.otf")
tlmgr search --file --global "LibertinusSerif-Regular.otf"
tlmgr.pl: package repository https://distrib-coffee.ipsl.jussieu.fr/pub/mirrors/ctan/systems/texlive/tlnet/ (not verified: pubkey missing)
libertinus-fonts:
	texmf-dist/fonts/opentype/public/libertinus-fonts/LibertinusSerif-Regular.otf

So we probably need to make an exception for this package

@jchiquet
Copy link
Author

jchiquet commented Sep 2, 2024

Thanks a lot for the insight, I changed the Issue title. I'll try to find out more about libertinus... or change fonts!

@cderv
Copy link
Collaborator

cderv commented Sep 2, 2024

I'll open an issue in tinytex R package too, because it seems the log message is not found. Maybe fontspec change its format.

Taking the example on R side, we see this in the log

[167] "! Package fontspec Error: "                                                                                                                                                                
[168] "(fontspec)                The font \"LibertinusSerif-Regular\" cannot be"                                                                                                                  
[169] "(fontspec)                found; this may be but usually is not a fontspec"                                                                                                                
[170] "(fontspec)                bug. Either there is a typo in the font name/file,"                                                                                                              
[171] "(fontspec)                the font is not installed (correctly), or there is"                                                                                                              
[172] "(fontspec)                a bug in the underlying font loading engine"                                                                                                                     
[173] "(fontspec)                (XeTeX/luaotfload)."   

And it is not match to any known error by the package. So it won't try to find the font and install. That is the problem. Once the rule is working on tinytex I'll adapt on Quarto.

@cderv
Copy link
Collaborator

cderv commented Sep 2, 2024

Thanks for the report @jchiquet. PR is up to teach Quarto about this new fontspec error.
Once tests passes I'll merge

@sam-b-rose
Copy link

@cderv using the latest version 1.16.18, the reported error was resolved for me. However, now the render command is getting caught on a different compilation error:

finding package for LibertinusSerif-Regular(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)
> 1 package to install
> installing libertinus-fonts (1 of 1)
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode

finding package for [LinBiolinum_K.otf(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)
ERROR:
compilation failed- no matching packages
Font \BiolinumKeyboard=[LinBiolinum_K.otf] not loadable: Metric (TFM) file or
 installed font not found.
<to be read again>

I'm new to Quarto and not really sure how to debug. Do you know might be going on here?

@mcanouil
Copy link
Collaborator

mcanouil commented Oct 2, 2024

@sam-b-rose This issue is closed, please open a new GitHub Discussion (or eventually a GitHub Issue) referencing this issue.
Do not forget to provide a reproducible example as demonstrated/documented in the Discussion and Issue template (read the text when opening a Discussion/Issue).

Sharing only an error message is unfortunately never enough to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working latex LaTeX engines related libraries and technologies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants