quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.75k stars 306 forks source link

monofont ignored with metropolis beamer theme #2545

Closed knuesel closed 1 year ago

knuesel commented 1 year ago

Bug description

The monofont setting is ignored when rendering the following with quarto 1.1.251 (on Pop!_OS 22.04):

---
monofont: Iosevka
format:
    beamer:
        theme: metropolis
        keep-tex: true
---

# Title

```
Some code
```

The setting works when rendering to pdf (--to pdf) instead of Beamer slides. It also works when rendering Beamer slides without theme: metropolis.

I think the problem is in this part of the template:

\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
  \setmonofont[]{Iosevka}
\fi
\usetheme[]{metropolis}

Here the \setmonofont[]{Iosevka} line has no effect because the metropolis theme later calls \setmonofont again.

I can work around this problem by adding the following in the YAML header:

        include-in-header:
            text: \setmonofont{Iosevka}

The meteropolis theme also calls \setsansfont so probably the sansfont setting is similarly ignored.

Looking at the other beamer themes in my texlive installation, I found one other that also overwrites font settings: the "Saint Petersburg" theme. This one also calls \setmainfont, so I guess the mainfont setting would also not work with this theme.

Minor side issue: the theme setting is not documented on https://quarto.org/docs/reference/formats/presentations/beamer.html (it is documented on https://quarto.org/docs/presentations/beamer.html however).

Checklist

cderv commented 1 year ago

I believe this related to an issue reported in Pandoc : https://github.com/jgm/pandoc/issues/6260 Not fixed yet though

It seems it is indeed in incorrect order. Beamer metropolis doc says:

The default font for metropolis is Fira. This can be easily changed using the standard font selection commands of the fontspec package. So if you prefer, for example, the Ubuntu font family, just add the following two commands after loading the metropolis theme

@knuesel can you try setting the font using include-in-header

---
format:
  beamer:
    theme: metropolis
    keep-tex: true
    include-in-header: 
      text: |
        \setmonofont[]{Iosevka}
---

This should but the included part after loading the theme. If this works, this is a workaround not a solution.

@dragonstyle Using our partials system, we may be able to inverse the order when format is beamer - or just patch the template dynamically when format is beamer and theme metropolis.

What do you think ?

knuesel commented 1 year ago

Ah right, this should probably be fixed in pandoc. The include-in-header fix does work (as mentioned in the original bug description :-) )

cderv commented 1 year ago

as mentioned in the original bug description :-) )

😅 oh yes sorry - I was all in explaining 😄

Ah right, this should probably be fixed in pandoc.

Yes I think so, but I don't know if this is easy or not because there templating system does not have much conditional logic. We have that in Quarto, so probably easier to add some handling for that ourselves. 🤔

knuesel commented 1 year ago

I've submitted a pandoc PR to fix the template there: https://github.com/jgm/pandoc/pull/8316

knuesel commented 1 year ago

The fix has been merged in pandoc. Not sure if you want to close the issue or wait until it's released and/or integrated in quarto's version...

cscheid commented 1 year ago

We will wait for it to be available in a new pandoc release so we can track, incorporate and test

cscheid commented 1 year ago

@knuesel we're now using Pandoc 3 and its new templates. Can you check on your side to confirm if this fixes your problems?

knuesel commented 1 year ago

The issue is still there, it seems the change to the LaTeX template in Pandoc was not carried over to the quarto templates?

dragonstyle commented 1 year ago

We attempted to update the templates to the Pandoc 3 templates, but something appears to be amiss in how we are doing this. I will take a closer look today.

dragonstyle commented 1 year ago

Ok I corrected the templates and the mono font appears to be behaving properly for Beam output (as of the latest pre-release of 1.3). Please let us know if you run into further issues.