quarto-thesis icon indicating copy to clipboard operation
quarto-thesis copied to clipboard

Math not rendering correctly in pdf

Open theorashid opened this issue 2 years ago • 6 comments

Description

Hi @eeholmes, I inserted a basic equation into the template Chapter 1. It renders fine on quarto equation preview in VSCode, but it does not render in the pdf. If I change the output to html, the equation renders as expected.

Steps to Reproduce

$$
\int_{A_i}{\lambda (\mathbf{x})}
$$

Does quarto not natively support math such as \int?

From html output: Screenshot 2023-01-20 at 17 06 47

From pdf: Screenshot 2023-01-20 at 17 04 51

theorashid avatar Jan 20 '23 17:01 theorashid

I'll check this out. It should definitely render fine in the pdf.

eeholmes avatar Jan 20 '23 18:01 eeholmes

Ok, this is very strange. Something in the cls file, which I didn't write, is causing a problem with the xelatex engine and causing it not to recognize that amsmath package is loaded.

In _quarto.yml, I can change the engine to pdflatex and it works. See last line here:

format:
  quarto-thesis-pdf: 
    urlcolor: red
    toclinkcolor: black
    toc-depth: 2
    pdf-engine: pdflatex

However I am not sure you have pdflatex. I am not sure that it comes by default with tinytex. I will try to figure out what in the (huge) cls file is causing xelatex to do this.

eeholmes avatar Jan 20 '23 20:01 eeholmes

Found the problem! I should have found it sooner since I have actually fixed a similar problem before for another Quarto extension.

The fontenc package causes xelatex not to render math correctly. So this line in _extension/partials/in-header.tex caused the problem:

\usepackage[T1]{fontenc}

I have commented that out and pushed the fix to GitHub. You can update the extension or just go into that file and delete or comment out that line. It is used for international letters, but Quarto should take care of that with its tex headers.

eeholmes avatar Jan 20 '23 21:01 eeholmes

Thanks for giving this a look. This bug is really strange. I found

$$
\int_{A_i}{\lambda (\pmb{\mu})}
$$ {#eq-ctl}

$$
\int_{A_i}{\lambda (\mathbf{\mu})}
$$ {#eq-ctl}

$$
\int_{A_i}{\lambda (\mathbf{x})}
$$ {#eq-ctl}

incorrectly gives for pdf Screenshot 2023-01-20 at 22 44 07

I don't know if it's worth reopening the issue because the use of \pmb is probably fine in most cases, I'm just used to using \mathbf from using LaTeX in the past. Interestingly, the html renders all 3 as expected

Screenshot 2023-01-20 at 22 44 33

theorashid avatar Jan 20 '23 22:01 theorashid

Those should render fine in pdf so I am reopening.

I tried running in just a default Quarto doc, so no cls file. The \mathbf{\mu} issue seems to be a xelatex problem. But the \mathbf{x} issue, is specific to quarto-thesis, so something in the header file is changing the behavior of \mathbf

With xelatex image

With pdflatex image

So for quarto-thesis, the issue is the \mathbf{x} not rendering. The problem was this line in the header

\usepackage{mathpazo}

xelatex is more picky than pdflatex about font conflicts and it didn't like this. Using Palatino in math is weird anyhow, to I deleted that. Now \mathbf{x} appears as intended. Note \mathbf{\mu} does not appear with xelatex but that's a xelatex problem.

eeholmes avatar Jan 21 '23 00:01 eeholmes

\pmb has more consistent and expected behaviour than \mathbf it seems. It's a strange error. I'll let you know if I find any more issues while I'm writing

theorashid avatar Jan 21 '23 09:01 theorashid