0

I am including some Julia code that uses Unicode characters, including Greek letters, in a verbatim environment. I've tried LaTeX, XeLaTeX, and LuaLaTeX (and am still open to using any of them), but haven't been able to get anything to work.

Here's an example line that contains most of the characters I need to render: μ ≤ ν₀ ≥ θ₁³

With \usepackage[utf8]{inputenc}, XeLaTeX and LuaLaTeX only render the cubed symbol. Attempting the xelatex solution from How to typeset greek letters (using the fontspec package and choosing DejaVu Serif) still only renders the cubed symbol. Attempting the solution from Greek and Latin letters in verbatim completely fails (XeLaTeX finished with exit code 1 and no further explanation), and attempting the other solution fails because the alphabeta package isn't available in the Fedora repository with TexLive. I've searched for the package itself and can only find documentation.

I'm completely at a loss. How can I get this to render correctly in a verbatim environment?

3
  • 1
    As always on the site, it is a good idea to provide a full but minimal self contained example that others can copy and use as is. This is obviously font related, so we need to know your exact setup. Might also be an idea to note exactly which latex installation you are using.
    – daleif
    Commented Feb 1, 2021 at 10:32
  • I found this related question: tex.stackexchange.com/q/404015/3929, it is obvious that you'll need to use a unicode aware engine equipped with a unicode monospace font.
    – daleif
    Commented Feb 1, 2021 at 10:40
  • 2
    never use inputenc with luatex or xetex Commented Feb 1, 2021 at 11:00

1 Answer 1

2

If you use xelatex or lualatex you just need to specify a monospace font that has the characters you need. I used Consolas here but there are many to choose from. DejaVu Sans Mono also has all the characters shown and may be easier to find available on on Windows machines.

enter image description here

\documentclass{article}

\usepackage{fontspec}
\setmonofont{Consolas}
% \setmonofont{DejaVu Sans Mono}
\begin{document}

\begin{verbatim}
abc
  αβγ
    → ←
μ ≤ ν₀ ≥ θ₁³
\end{verbatim}
\end{document}

With DejaVu Sans Mono it looks like

enter image description here

11
  • Does that font come with TeXLive? Because I tried it via the URL in my comment above and it was not found on my system
    – daleif
    Commented Feb 1, 2021 at 11:41
  • @daleif no it's a standard windows one I think. If your browser is showing the code block in this answer with all the characters look in its font menu to see which font it is using, and you can use the same. (in firefox at least that is "inspect element" then look at the font tab in the inspector) Commented Feb 1, 2021 at 11:46
  • It's probably not installed on my Linux then
    – daleif
    Commented Feb 1, 2021 at 11:59
  • @daleif this works as well \setmonofont{DejaVu Sans Mono} probably better for linux? Commented Feb 1, 2021 at 12:00
  • 1
    @daleif I added a note to the answer Commented Feb 1, 2021 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .