1

I recently moved over to luaLaTeX from pdfLaTeX which means I am no longer quite so font-constrained. I found this answer which shows how to load this alphabet of upright Greek letters instead of the math alphabet. I don't want to load them in place of the math alphabet, I want that to stay italic. I want to use them for commands like \chemalpha to replace the commands from the chemgreek package. Alternatively, making chemgreek use this alphabet would work, though I can manually write each command if need be.

I made this example, but it doesn't actually work, it replaces the wrong alphabet and the \newcommand{\chemalpha}{α} don't actually DO anything as it has no idea what α is.

\documentclass{article}

\usepackage[math-style=upright]{unicode-math} \setmathfont{Latin Modern Math} \setmathfont[range=up/{Latin,latin,Greek,greek}]{CMU Serif Upright Italic} \usepackage{cfr-lm}

\newcommand{\chemalpha}{α} \newcommand{\chembeta}{β} \newcommand{\chemeta}{η} \newcommand{\chemkappa}{κ}

\begin{document} ( \alpha + \beta = \pi )

([^{\text{n}}\text{Bu}_4 \text{N}]_2 [(\text{UO}_2 )_2 (µη^{2}:η^{2}O_2 )(NO_3 )_2 (µ\text{Au(CN)}_2 )_2 ])

\chemalpha \chembeta \chemeta \chemkappa

\end{document}

Canageek
  • 17,935
  • You probably want the \mathrm font chemical elements. If you use \text, the formatting of the surrounding text will bleed through. – Davislor Dec 29 '20 at 01:07
  • You can \setmathrm{CMU Serif} or load newcomputermodern to get a Computer Modern font that contains upright Greek. – Davislor Dec 29 '20 at 01:11
  • Chemical formulas traditionally have not used upright italic style, but if you wanted to use that \setmathfont[range=... command, you would use \symup to get the upright symbols from the math alphabet. Note that there are upright Greek letters in every OpenType math font. – Davislor Dec 29 '20 at 01:13
  • cfr-lm is a legacy package that you would not use together with fontspec. – Davislor Dec 29 '20 at 01:14
  • Finally, your \chemalpha, etc., are not working because you used them in text mode instead of math mode. The default text font, Latin Modern Roman, has no Greek letters. They will work if you load New Computer Modern or CMU Serif, which do. – Davislor Dec 29 '20 at 01:16
  • 1
    \usepackage{newcomputermodern}\usepackage{chemgreek}\selectchemgreekmapping{fontspec} seems to work just nicely – cgnieder Dec 29 '20 at 08:47
  • @cgnieder That is perfect, since I was already using chemgreek via chemformula. Now I just need to figure out how to use the right version of κ – Canageek Dec 29 '20 at 20:59

2 Answers2

1

Glad you found my older answer helpful. First, a MWE:

\documentclass{article}
\tracinglostchars=2

\usepackage{newcomputermodern} % Alternatively, \setmathrm{CMU Serif} to load an upright font that contains Greek.

\newcommand\chem[1]{\mathrm{#1}} \newcommand\chemalpha{\chem\mupalpha} % \chem α would work too. \newcommand\chembeta{\chem\mupbeta} \newcommand\chemeta{\chem\mupeta} \newcommand\chemkappa{\chem\mupkappa}

\begin{document} ( \alpha + \beta = \pi )

([^{\chem{n}}\chem{Bu}_4 \chem{N}]_2 \bigl[(\chem{UO}_2 )_2 (\chem{µη}^{2}:\chem{η}^{2}\chem{O}_2 )(\chem{NO}_3 )_2 \bigl( \chem{µ}\chem{Au}(\chem{CN})_2 \bigr)_2 \bigr])

( \chemalpha \chembeta \chemeta \chemkappa ) αβηκ \mupalpha\mupbeta\mupeta\mupkappa

\end{document}

New Computer Modern sample

Chemists traditionally don’t use upright italic style for chemical formulas, but if you did want to, you’d write \symup{\alpha} in math mode to use the letters you set with \setmathfont[range=up]. To use the upright italic style in text mode, you would probably set up the {ui} shape similarly to the interface of cfr-lm.

What you probably want to do here is to set your \mathrm font to one that has Greek letters, such as New Computer Modern or CMU Serif. The default font, Latin Modern, doesn’t, and that’s why it wasn’t working for you. I introduce a command \chem so you can tweak it or switch to another font (with something like \textnormal{\chemfont #1}, or by declaring a new math font face) by changing that one line.

I took a few liberties with the source. You don’t want to use \text here, since it makes the formatting of the surrounding text bleed through, and therefore might give you CN. If you need to use a main font that does not contain Greek, you can \setmathrm{NewComputerModern}.

I changed the formatting slightly, to make nested outer parentheses slightly bigger than inner parentheses, and the brackets around those the same size.

You also would only want to load cfr-lm if you are compiling in PDFTeX.

You do, however, want to set \tracinglostchars=2. This will give you a warning if you try to use a character that the current font does not have, which is the bug you were getting with \chemalpha, etc. By default, the warning will be silently buried in the middle of your .log file.

Davislor
  • 44,045
  • Oh yeah, I would rather just non-italic upright Greek letters as that is what I normally see for hapto, dento, and bridging notation which is what I'm using them for – Canageek Dec 29 '20 at 02:01
  • @Canageek Does that MWE work for you? I left Greek math variables italicized, but you can also \usepackage[math-style=upright]{unicode-math} before \usepackage{newcomputermodern} to change those back. – Davislor Dec 29 '20 at 02:03
  • I'll be testing it today. Thanks for the great introduction to LuaLaTeX – Canageek Dec 29 '20 at 18:30
  • By the way, that isn't the actual way I'd write a chemical formula, I would use the chemformula package for that, I just didn't want to introduce it to a MWE. – Canageek Dec 29 '20 at 20:15
1

Based on the comment by cgnieder

\usepackage{newcomputermodern}\usepackage{chemgreek}\selectchemgreekmapping{fontspec}

is very simple and works with my existing setup almost perfectly.

Canageek
  • 17,935