TeX - LaTeX Asked on July 31, 2021
This is a follow up to my previous question. I want listings
to be able to handle valid python identifiers in listings using pdfLaTeX.
The MWE literate_mwe.tex
produces the following output from the input file literate_test.txt
:
The commands to listings
to produce these glyphs can be seen here. Notably, the third and last lines are supposed to have bold upright serif characters (latin letters and numbers resp.) but instead they only produce upright serif characters. The command to produce bold upright "g", for example, is almost exactly that given in the bm
documentation (see section 3.1): bm{{mathrm{g}}}
.
However, clearly this works for the other font families: for example, bm{{mathsf{0}}}
works just fine in the last row to produce an upright bold sans-serif zero.
How can I diagnose what’s happened to bm
? How can I avoid or fix this behavior to obtain upright bold serif math?
EDIT: changing the bolding command for just the upright serif characters to e.g. mathbf{g}
causes pdfLaTeX to choke and emit Too many math alphabets used in version normal
when it hits the first monospace character. Could bm
be silently swallowing the error then?
Legacy LaTeX is limited to sixteen math alphabets. I would strongly, strongly recommend that you port your code to unicode-math
and LuaLaTeX if you can. The OpenType successor to fourier
is fourier-otf
.
Even if someone is forcing you to use PDFTeX, you might want to use isomath
, which defines the alphabets mathbfit
, mathsfbfit
, and so on, and also allows you to load an upright, OML-encoded Utopia math alphabet with Greek letters as mathrm
and mathbf
.
Even if you don’t do that, I’d highly recommend using standard names like mathbf
and mathbfsfit
in your source, rather than bm{mathrm{x}}
. You can still define them as providecommandmathbfsfit[1]{boldsymbol{mathsfit{#1}}}
and so on. (It is preferable to use boldsymbol
in this context instead of bm
, as it takes up fewer math alphabets and is compatible with more packages.) Note that mathalpha
defines bolder versions of many other math alphabets, including calligraphic and blackboard-bold, so you should use those if you load it.
The minimal fix for your MWE is to re-declare mathrm
and mathbf
as the mdput
family (Math Design Utopia, compatible with the Utopia used by fourier
) in the OML encoding, which supports Greek letters. I likewise define mathsfit
to use the math alphabet from sansmathfonts
, which contains Greek.
When you set your math font to an encoding that supports Greek, you can use mathrm{alpha}
, mathbf{beta}
or boldsymbol{mathrm{gamma}}
, but I also define upalpha
and the rest for backward-compatibility with upgreek
. (The fourier
package has its own versions, but you had been using upgreek
.) In order to be able to use DeclareMathSymbol
on them, I redefine mathrm
as an alias for the new upletters
symbol font, saving a few math alphabets.
documentclass{article}
tracinglostchars=2
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{fourier}
usepackage{fontaxes}
usepackage{amsmath, amsthm, amssymb}
usepackage[bb=boondox, cal=boondox]{mathalpha}
providecommandbm[1]{boldsymbol{#1}}
letmathbboldmathbb
AtBeginDocument{% thanks fourier
letmathbbrelax
newcommand{mathbb}[1]{mathbbold{#1}}
}
letmathsfitundef
DeclareMathAlphabet{mathsfit}{OML}{cmssm}{m}{it}
SetMathAlphabet{mathsfit}{bold}{OML}{cmssm}{b}{it}
DeclareSymbolFont{upletters}{OML}{mdput}{m}{n}
SetSymbolFont{upletters}{bold}{OML}{mdput}{b}{n}
DeclareSymbolFontAlphabet{mathrm}{upletters}
DeclareMathAlphabet{mathbf}{OML}{mdput}{b}{n}
DeclareMathSymbol{upGamma}{mathalpha}{upletters}{"00}
DeclareMathSymbol{upDelta}{mathalpha}{upletters}{"01}
DeclareMathSymbol{upTheta}{mathalpha}{upletters}{"02}
DeclareMathSymbol{upLambda}{mathalpha}{upletters}{"03}
DeclareMathSymbol{upXi}{mathalpha}{upletters}{"04}
DeclareMathSymbol{upPi}{mathalpha}{upletters}{"05}
DeclareMathSymbol{upSigma}{mathalpha}{upletters}{"06}
DeclareMathSymbol{upUpsilon}{mathalpha}{upletters}{"07}
DeclareMathSymbol{upPhi}{mathalpha}{upletters}{"08}
DeclareMathSymbol{upPsi}{mathalpha}{upletters}{"09}
DeclareMathSymbol{upOmega}{mathalpha}{upletters}{"0A}
DeclareMathSymbol{upalpha}{mathalpha}{upletters}{"0B}
DeclareMathSymbol{upbeta}{mathalpha}{upletters}{"0C}
DeclareMathSymbol{upgamma}{mathalpha}{upletters}{"0D}
DeclareMathSymbol{updelta}{mathalpha}{upletters}{"0E}
DeclareMathSymbol{upepsilon}{mathalpha}{upletters}{"0F}
DeclareMathSymbol{upzeta}{mathalpha}{upletters}{"10}
DeclareMathSymbol{upeta}{mathalpha}{upletters}{"11}
DeclareMathSymbol{uptheta}{mathalpha}{upletters}{"12}
DeclareMathSymbol{upiota}{mathalpha}{upletters}{"13}
DeclareMathSymbol{upkappa}{mathalpha}{upletters}{"14}
DeclareMathSymbol{uplambda}{mathalpha}{upletters}{"15}
DeclareMathSymbol{upmu}{mathalpha}{upletters}{"16}
DeclareMathSymbol{upnu}{mathalpha}{upletters}{"17}
DeclareMathSymbol{upxi}{mathalpha}{upletters}{"18}
DeclareMathSymbol{uppi}{mathalpha}{upletters}{"19}
DeclareMathSymbol{uprho}{mathalpha}{upletters}{"1A}
DeclareMathSymbol{upsigma}{mathalpha}{upletters}{"1B}
DeclareMathSymbol{uptau}{mathalpha}{upletters}{"1C}
DeclareMathSymbol{upupsilon}{mathalpha}{upletters}{"1D}
DeclareMathSymbol{upphi}{mathalpha}{upletters}{"1E}
DeclareMathSymbol{upchi}{mathalpha}{upletters}{"1F}
DeclareMathSymbol{uppsi}{mathalpha}{upletters}{"20}
DeclareMathSymbol{upomega}{mathalpha}{upletters}{"21}
DeclareMathSymbol{upvarepsilon}{mathalpha}{upletters}{"22}
DeclareMathSymbol{upvartheta}{mathalpha}{upletters}{"23}
DeclareMathSymbol{upvarpi}{mathalpha}{upletters}{"24}
DeclareMathSymbol{upvarrho}{mathalpha}{upletters}{"25}
DeclareMathSymbol{upvarsigma}{mathalpha}{upletters}{"26}
DeclareMathSymbol{upvarphi}{mathalpha}{upletters}{"27}
usepackage{listings}
input{literate.tex}
pagestyle{empty}
begin{document}
lstinputlisting{literate_test.txt}
end{document}
Once we redefine each math alphabet to cover Latin and Greek in both bold and regular weights, the document does not run out of math alphabets. If you genuinely need so many that this is impossible, the workaround is to display the math alphabets as text, for example newcommandmathsfit[1]{textnormal{sffamilyitshapeselectfont #1}}
. You can also display a symbol that doesn’t vary according to the math alphabet or version with, e.g. newcommandQED{mathord{text{usefont{LS1}{stix}{m}{n}symbol{"D1}}}}
. This does not use up a math alphabet.
Rather than load bm
and nearly-disabling it by setting bmmax
to 0, I here redefine it as boldsymbol
. (Don’t do this in your source! Use meaningful names like vectorsym
and tensorsym
.)
There are also a few other tweaks, such as mathalpha
for mathalfa
, removing a few packages that I made redundant, and replacing fix-cm
with fontaxes
when you are not using Computer Modern.
Correct answer by Davislor on July 31, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP