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

Equation doesn't work in PDF but does in HTML #298

Closed
henry2004y opened this issue Aug 20, 2022 · 3 comments
Closed

Equation doesn't work in PDF but does in HTML #298

henry2004y opened this issue Aug 20, 2022 · 3 comments

Comments

@henry2004y
Copy link
Contributor

Hi,

I am having some issues with the PDF generation functionality. The html version works fine for most of the math (not all, because some commands from certain LaTeX packages are not loaded), but a PDF output cannot be generated from the same markdown files.

The problematic LaTeX expression is this:

$$
F_r = q(\underbrace{v_\theta B_z}_{\small{1}} - v_z \cancel{B_\theta})
$$

and specifically, \cancel:

error: halted on potentially-recoverable error as specified
Error producing PDF.
! Undefined control sequence.
l.712 ...e{v_\theta B_z}_{\small{1}} - v_z \cancel

Here is a screenshot of the above expression in the html version (for simplicity, I only include the LaTeX of the first equation):

Screenshot 2022-08-20 at 14-32-30 Nonuniform B Field - Key Notes of Plasma Physics(1)


I am curious why the PDF generation with pandoc produces errors whereas the html version works fine? Do they include different scopes of packages underneath?

@rikhuijzer rikhuijzer changed the title PDF generation Equation doesn't work in PDF but not in HTML Aug 21, 2022
@rikhuijzer rikhuijzer changed the title Equation doesn't work in PDF but not in HTML Equation doesn't work in PDF but does in HTML Aug 21, 2022
@rikhuijzer
Copy link
Collaborator

I am curious why the PDF generation with pandoc produces errors whereas the html version works fine? Do they include different scopes of packages underneath?

Yes, there is completely different software underneath. The TeX version is rendered by a TeX math renderer like is normally the case when using LaTeX. However, for webpages the TeX renderer is way too slow and it is difficult to get the alignment of images right when one would use that. To solve this, KaTeX and MathJax exist. The Books.jl package uses MathJax.

The problem here is that the cancel package is missing from the set of used TeX packages. You can add it by adding the following to your metadata.yml from Books.jl v2.0.3 onwards:

extra-pdf-header: |
  \usepackage{cancel}

This extra-pdf-header can be used to add any extra header to the PDF generation. In this case, only \usepackage{cancel} is needed. I tried to build the equation that you mentioned and it works for me.

@i-walker
Copy link

Is there a way to check if all my added packages are added?
I added

header-includes: |
  \usepackage{cancel, amssymb, amsmath, siunitx, physics2, fixdif, derivative, systeme, multicol, tikz, pgfplots}

But upon using them the images from tikz are not rendered nor when I use other packages?

@rikhuijzer
Copy link
Collaborator

Is there a way to check if all my added packages are added? I added

header-includes: |
  \usepackage{cancel, amssymb, amsmath, siunitx, physics2, fixdif, derivative, systeme, multicol, tikz, pgfplots}

But upon using them the images from tikz are not rendered nor when I use other packages?

Yes you can check that by going to the directory of the generated files (where the generated PDF is too) and look at the .tex file. Books.jl will always put that file there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants