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

Convert to HTML is fine, but Convert to PDF ignores Greek letters #1673

Closed
ibehnam opened this issue Nov 16, 2021 · 6 comments
Closed

Convert to HTML is fine, but Convert to PDF ignores Greek letters #1673

ibehnam opened this issue Nov 16, 2021 · 6 comments

Comments

@ibehnam
Copy link

ibehnam commented Nov 16, 2021

This has been discussed many time here and on other forums, but I still don't know how to get Jupyter to print Greek letters when I convert the notebook to PDF. Interestingly, if converted to HTML, everything is fine.

When converted to PDF:
image

When converted to HTML:
image

I've tried using CLI pandoc and tweaking the settings (e.g., changing the font or using xelatex instead of pdflatex), but nothing seems to work. And since these Greek letters are part of my code, I can't just replace them with something that's known to Latex.

@MSeal
Copy link
Contributor

MSeal commented Nov 17, 2021

Try doing the webpdf conversion -- it uses HTML to generate the PDF instead of LaTeX and generally has a lot fewer unsupported renderings.

@ibehnam
Copy link
Author

ibehnam commented Nov 18, 2021

Try doing the webpdf conversion -- it uses HTML to generate the PDF instead of LaTeX and generally has a lot fewer unsupported renderings.

Thanks. I tried that, but it breaks code and code outputs across pages:
image

@cgevans
Copy link
Contributor

cgevans commented Dec 7, 2021

Having unicode letters work in LaTeX differs depending on whether pdflatex or xelatex/lualatex is being used. The current template

For xelatex/lualatex, having \usepackage{unicode-math} in the template would allow for Greek characters to work reasonably in math (but breaks pdflatex). The ucs package isn't needed / is detrimental.

For pdflatex, the current template does include \usepackage[mathletters]{ucs}, but the ucs package also needs \usepackage[utf8x]{inputenc} to come after it, and so with the current template, unicode math won't work.

Pandoc's current template never uses ucs, and uses unicode-math if xelatex/lualatex is being used.

I'll see if I can fix up the template to have this work, hopefully for both math and text.

cgevans added a commit to cgevans/nbconvert that referenced this issue Dec 7, 2021
The current latex base template uses the ucs package with mathletters,
but as it does not also set utf8x on inputenc, the ucs package does
not work as intended, and Greek letters do not appear in math.

As utf8x and ucs are somewhat outdated and problematic, this PR uses
a few conditions to try to enable Greek letters in both math and text.

For pdflatex, if the alphabeta package (part of greek-inputenc, and
not necessarily installed) is present, this is used, as it better
supports Greek math and text, including diacritics.  It it is not,
ucs with mathletters is used, which will allow math, and some text,
though diacritics will cause an error.

For xelatex and lualatex, this instead uses unicode-math, which
handles math well but does not support pdflatex.  While this
arrangement does support text, note that by default, the fonts used
are unlikely to include support for Greek text, and the glyphs will be
omitted (both for text and for monospace text), particularly since
Latin Modern does not support Greek text.  I have an additional change
which uses Computer Modern Unicode if available, but I'd like to keep
these separate, as it's unclear to me that setting the font in this
template would be a good idea.

Mathpazo for pdflatex is removed for consistency with xelatex/lualatex
output, and the position of the conditional is moved to avoid an order
conflict with the ams packages; this more closely matches the position
of unicode-math in pandoc's template.
@t-makaro
Copy link
Contributor

I haven't looked at this in a while, but I'm fairly certain that we should be using \usepackage[utf8]{inputenc} and not the utf8x package. They are similar, but utf8x dated. I have been meaning to test it out for a while, but I haven't gotten around to it.

@cgevans
Copy link
Contributor

cgevans commented Jan 26, 2022

I think that \usepackage[mathletters]{ucs} needs utf8x specifically, not utf8; utf8x is actually in the ucs package. I think both ucs and utf8x are dated, yes; for pdflatex, the code here uses the alphabeta package, if it is installed, and only uses ucs and utf8x as a fallback if it isn't. For lualatex/xelatex, it uses unicode-math (though Greek text will not work with the default font in those cases; see #1688).

@jpgoldberg
Copy link

Somewhere, I have get to find where, the generated LaTeX uses latinmodern fonts. latin modern mono does not include Greek.

From my xelatex logs:

Missing character: There is no φ (U+03C6) in font [lmmono10-regular]:!

I have not found out where I can change this. (I can manually edit the generated LaTeX file, but I want to build from a notebook to PDF

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

5 participants