Unicode characters in Julia Markdown not exported to pdf

Hi there,

I’m relatively new to Julia and I am working in VS Code on a Mac OS. When I try to export my .jmd file which contains greek letters (\alpha, \varepsilon etc.), I get the following error message:

Info: Weaving chunk 1 from line 10
└ progress = 0.0
┌ Info: Weaved all chunks
└ progress = 1
[WARNING] Missing character: There is no α (U+03B1) (U+03B1) in font [lmmono12-regular]:!
[WARNING] Missing character: There is no μ (U+03BC) (U+03BC) in font [lmmono12-regular]:!
[WARNING] Missing character: There is no ε (U+03B5) (U+03B5) in font [lmmono12-regular]:!
[ Info: Weaved to … ]

This is the example .jmd file for which I get the error:

---
title: Test title

weave_options:
    doctype: pandoc2pdf
---

Test

α = 2;
μ = 3;
ε = 4;

I export it to pdf by using Weave (I run weave("filename.jmd') in Julia terminal in VS Code). The pdf I get displays my code chunk as:

I’ve tried including a template .tex file and using minted but the output was the same regardless.

---
title: Test title

weave_options:
    doctype: pandoc2pdf # I also tried it with pandoc and md2tex, neither worked
    template: template.tex
    minted: true
---

My template.tex file is as follows:

\documentclass{article}

\usepackage{fontspec}

\usepackage{polyglossia}

\usepackage{minted}

\usepackage{unicode-math}

\setmonofont{DejaVu Sans Mono}[Scale=MatchLowercase]

\begin{document}

$body$

\end{document}

How can I remedy this? I’ve tried quite a few workarounds suggested here, but nothing seems to have worked.

Thanks!

1 Like

Your errors suggest that the font doesn’t have the characters you need. I’d start with trying a font which does.

I’m sure there’s a way to define fallback fonts, so that the characters available in your main font render in that face, and the ones which aren’t come from the fallback. I don’t happen to know what that way is, however.

3 Likes

Thanks for responding!

My understanding of the problem is that the issue comes from my LaTeX engine and Pandoc not being able to print the characters I need. This is only a problem when the characters are inside code chunks, and \alpha is exported into a pdf normally when it’s outside a code chunk.

I’m not sure whether this fallback font should be specified in my LaTeX compiler, in VS Code or somewhere else.

I don’t know much about LaTeX, but perhaps the font used in code blocks is different from the normal font of the document, because usually code is shown with a monospace font. Maybe, the font your LaTeX environment uses for code blocks does not support these characters?

1 Like

There is GitHub - cormullion/juliamono: repository for JuliaMono, a monospaced font with reasonable Unicode support. which should support all these symbols

3 Likes

This isn’t strictly speaking a Julia problem, or with any Julia package. Nor for VS Code.

I seem to have confirmed (as I suspected, still wanted to help) it’s a pandoc problem (or as explained simply using a different font and/or fallback the likely solution; how? potentially though by telling Weave):

I started looking if Weave.jl produced the error, i.e. if it’s part if its error messages, but I could only support it running pandoc, and thus indirectly it produces a warnining (as could have happened in R and other ecosystems):

1 Like

Thank you for your replies.

I’ve only used RMarkdown before and I have not dealt with issues with Pandoc before. From my own testing attempts, I could not get Weave to read in any header_includes text and my test output was indifferent to solutions suggested here

Could you please explain how I could implement any of the solutions suggested in the links in the replies above into Julia Markdown files?

Would this mean running multiple commands in the Terminal, all in order to get a pdf out of my .jmd file? Would I still be able to continue using Weave or would it have to be combined with running some Pandoc lines in the terminal?

Apologies if these seem like very basic questions, this type of pdf exporting is quite new to me.

One thing I noticed was that your error said:

There is no α (U+03B1) (U+03B1) in font
 [lmmono12-regular]:!

and yet you had asked for

\setmonofont{DejaVu Sans Mono}

lmmono12-regular is the Latin Modern Mono font; whatever its other virtues, it doesn’t have any lower-case greek glyphs, so it’s not a good choice for you.

But why was it chosen? My guess is that the \setmonofont request didn’t actually work, for some reason. I think the syntax looks right… I don’t know how font-finding works in this particular environment.

You can specify the exact name of a font file on your system, rather than rely on the font-matching process. For example:

\setmonofont{DejaVuSansMono.ttf}

In my own very limited use of LaTeX I used this snippet:

\usepackage{fontspec}
\usepackage{unicode-math}
\usepackage[utf8]{inputenc}
\usepackage{minted}

\setmonofont{JuliaMono-Regular.ttf}[
    Path = /Users/me/Library/Fonts/,
    Contextuals = Alternate,
    CharacterVariant=1,
    Scale = MatchLowercase,
    BoldFont = JuliaMono-Bold.ttf
]

which points directly to the font I wanted to test, and chooses the various OpenType options that are available.

I also noticed that weave() has an option keep_unicode:

* `keep_unicode::Bool = false`: If `true`, do not 
convert unicode characters to their respective 
latex representation. This is especially useful 
if a font and tex-engine with support for 
unicode characters are used

I don’t understand this, but perhaps Weave/LaTeX users do…

1 Like

In markdown, you can use

header-includes:
- |
  ```{=latex}
  \setmonofont[Path=./]{Hack-Regular.ttf}

in the header so that the latex convertion will add the correct line to the latex header. Then simply add the font file to your repository.

ps: the forum is not rendering what i meant correctly, take a look at the code of my message.