0

I am able to display the Greek letter θ (the only one I am interested in) in text mode, thanks to \usepackage[euler]{textgreek}. I just copy and paste θ into my text, and it looks fine. Now I want it to be in courier font, as I use that font to represent variables from my Python code. In short, I have a Python variable named θ_start and I want it to appear as \texttt{θ\_start} in Latex. Problem, \texttt has no effect on θ: it leaves it unchanged, in whatever standard font is used in my document. How to fix this? Is there an alternative to \texttt that could handle this?

(and no this is not a joke, I actually have variables in Greek letters in my Python code, and it works without problem and helps the reader makes the link between the code and my research paper; however, in LaTeX, that's where the problem happens)

1
  • you could use lualatex and unicode fonts, eg whatever font you have in your python editor. classic tex tt font only has 127 (OT1) or 256 (T1) characters, and has no Greek. Commented Aug 16, 2022 at 21:26

1 Answer 1

2

produced with lualatex picking a couple of well known Windows system fonts.

\documentclass{article}
\usepackage{fontspec}

\setmainfont{Times New Roman}
\setmonofont{Consolas}

\begin{document}

\texttt{θ\_start}

\begin{verbatim}

θ_start αβ
   
\end{verbatim}

\end{document}
2
  • Thank you. I have to figure out which fonts work. It works if I use \setmainfont{Times New Roman} in the preamble. Without it, not sure which font is the default one, but the θ is not rendered (it's blank). Maybe I can use "Times New Roman" only for θ. Then I have to figure out how to add the bibliography back, but that's another issue (I use MikTex, and for the first time, I chose the LuaLaTeX option for Typset, I did not know it was there) Commented Aug 16, 2022 at 22:21
  • The version of Courier New that comes with Windows or Office supports Greek text. Some free alternatives that come as complete font families with math support are: Fira Mono, Libertinus Mono, and DejaVu Sans Mono.
    – Davislor
    Commented Aug 17, 2022 at 1:10

You must log in to answer this question.

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