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?

zaen
  • 133
  • 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 Feb 01 '21 at 10:32
  • I found this related question: https://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 Feb 01 '21 at 10:40
  • 2
    never use inputenc with luatex or xetex – David Carlisle Feb 01 '21 at 11:00

1 Answers1

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

David Carlisle
  • 757,742
  • 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 Feb 01 '21 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) – David Carlisle Feb 01 '21 at 11:46
  • It's probably not installed on my Linux then – daleif Feb 01 '21 at 11:59
  • @daleif this works as well \setmonofont{DejaVu Sans Mono} probably better for linux? – David Carlisle Feb 01 '21 at 12:00
  • That helps on my system it seems (DesaVu Sans Mono) – daleif Feb 01 '21 at 12:04
  • 1
    @daleif I added a note to the answer – David Carlisle Feb 01 '21 at 12:05
  • If you want a variant of Computer Modern, both New Computer Modern Mono (Regular or Book) and CMU Unicode Typewriter Text have Greek. – Davislor Feb 01 '21 at 16:19
  • @Davislor I tested newcm this morning,that had greek but not the subscripts, havent checked CMU version – David Carlisle Feb 01 '21 at 16:20
  • @DavidCarlisle Another alternative would be to use minted, where you could define a verbatim as \textsubscript{0}. – Davislor Feb 01 '21 at 16:26
  • @DavidCarlisle And DejaVu Sans Mono is in the dejavu-otf package, for both TeX Live and MikTeX. – Davislor Feb 01 '21 at 16:27
  • @Davislor yes even for verbatim you could use newunicodechar (or other things) and fake up the subscript) but they are really different answers. I wanted here to show the basic question answered with just \usepackage{fontspec} and \setmonofont with no additional packages and no coding. You can add bells and whistles but it should "just work". – David Carlisle Feb 01 '21 at 16:32