Letters and numbers in math do not use "mainfont" nor "mathfont" - latex

I notice that, in math mode (i.e., in quarto, $$...$$ or $...), letters and numbers are being set in a default font irrespective of the mainfont or mathfont. Thus, variable names and numbers are being typeset in a different font.
mathfont does have effect on math operators, e.g. \log will be typeset using the mathfont. However, letters and numbers are not. Is this expected behavior?
I know a workaround. That is to use \mathit{} for the entire equation, then use \mathrm{} for numbers that need to be upright. Then it looks right, but it makes the coding so much more heavy (than it already may be).
Compile the following document to see the issue:
---
documentclass: article
mainfont: Lato
mathfont: Lato
---
$$ y = 123\cdot\log{x} $$
$$ \mathit{y = \mathrm{123}\cdot\log{x}} $$
(Eventually substitute your own font). The second equation looks how it ought to be. In the irst equation, only operators (log) use the mathfont. Other items use a default "latex" font (the same you have when not specifying a mainfont).

Not every font contains the necessary math symbols, Lato does not contain them. You'll see a warning like this in your .log file:
Package fontspec Warning: Font "Lato" does not contain requested Script
(fontspec) "Math".
In particular for sans serif fonts, there aren't a lot to choose from and the few which exist are often incomplete.
One sans serif font which provides a fairly good coverage is Fira Math (... but it's design might be a bit polarizing)
---
documentclass: article
mainfont: Lato
mathfont: Fira Math
format:
pdf
---
$$ y = 123\cdot\log{x} $$
$$ \mathit{y = \mathrm{123}\cdot\log{x}} $$
If you'd like to use the letters and numbers from the text font in math mode, you could use the mathastext package:
% !TeX TS-program = lualatex
\documentclass{article}
\usepackage[no-math]{fontspec}
\setmainfont{Lato}
\usepackage{mathastext}
\begin{document}
\[ y = 123\cdot\log{x} \]
\end{document}

Related

LaTex how to edit this equation?

I'm having issues turning this word equation into a LaTex equation. It's coming out looking dodgy, please help!
I added a screen shot of the equation I want, and what I end up getting when I copy and paste into LaTex:
WORD:
LATEX CODE:
\mathrm{=\ }\mathrm{C}_\mathrm{0}\mathrm{[1-}6(Dt)1/2aπ2-3Dta2] + 12(Dt)1/2an = 1∞exp(na(Dt)1/2)
and therefore nothing comes out and LaTex doesn't let me run it.
This is absolutely not a proper LaTeX equation code. I don't know what you know about LaTeX, but you cannot just copy and paste from Word or any software to you LaTex editor. Plus, you need to provide your full code for anyone being able to help you.
Anyway, running this MWE should work :
\documentclass[11pt, a4paper, twoside]{report}
% ===== PACKAGES DECLARATION =====
\usepackage{mathtools} % Replaces amsmaths + more features
\usepackage{amsfonts} % Maths fonts package
% ===== DOCUMENT BODY =====
\begin{document}
\begin{equation} % optional : use the "equation*" environment to remove equation number
% optional : use traditional math font by removing the \mathrm{} command
\mathrm{X = C_0 \left[ 1 - \frac{6(Dt)^{1/2}}{a \pi^2} - \frac{3Dt}{a^2}\right] + \frac{12(Dt)^{1/2}}{a} \sum_{n=1}^\infty \exp\left(\frac{na}{(Dt)^{1/2}} \right)}
% optional : remove auto-sized brackets by removing the \left and \right commands
\end{equation}
\end{document}
As written in the code, you may want to remove the equation number and the big auto-sized brackets (that are more readable in my opinion). Just remove the corresponding commands. Also, you should consider using the "normal" math font and not the roman one that is clearly different from the text and helps the reader to separate equations from inline small expressions you could insert in your document.
One first sketch:
\documentclass{article}
\begin{document}
\[
C_0\left[1-\frac{6(Dt)^{\frac{1}{2}}}{a\pi^2}-\frac{3Dt}{a^2}\right]+%
\frac{12(Dt)^{\frac{1}{2}}}{a}\sum^{\infty}_{n=1}%
\exp\left(\frac{na}{(Dt)^{\frac{1}{2}}}\right)
\]
\end{document}
No packages required. The output:
Than you can tune the math fonts and anything else.

How may I convert a three-digit Arabic number (Perl [0-9][0-9][0-9]) to a three-digit English representation ([zero-nine][zero-nine][zero-nine])

The alternative is to use Roman numerals, for which a package is
available. I am using the LaTeX catchfile package and the \input{}
command to associate a title in a set of TITLE files with \section{}
commands in a set of DOCUMENT files.
I would like to have a file of catchfile definitions, with records
such as:
\CatchFileDef{\t-001}{title-001.tex}{}
\CatchFileDef{\t-002}{title-002.tex}{}
\CatchFileDef{\t-003}{title-003.tex}{}
But LaTeX does not allow numerical labels such as "\title-003".
Roman numerals are workable:
\CatchFileDef{\ti}{title-001.tex}{}
\CatchFileDef{\tii}{title-002.tex}{}
\CatchFileDef{\tiii}{title-003.tex}{}
but are ugly in comparison with:
\CatchFileDef{\tzerozeroone}{title-001.tex}{}
\CatchFileDef{\tzerozerotwo}{title-002.tex}{}
\CatchFileDef{\tzerozerothree}{title-003.tex}{}
On possibility to convert digits into their corresponding words is the numspell package:
\documentclass{article}
\usepackage{numspell}
\usepackage{pgffor}
\begin{document}
\foreach \x in {0,...,9}{
\foreach \y in {0,...,9}{
\foreach \z in {0,...,9}{
\x\y\z : \numspell{\x}\numspell{\y}\numspell{\z}
}}}
\end{document}
In an hour or two, using Emacs, I created a look up table which solved the problem. The English spelling of Arabic numerals appears to be less prone to error than is the use of Roman numerals.

Latex biblatex: bibliography titles aren't doing a break line, they overflow instead [ ]

I recently discovered a problem in my bibliography and I somehow can't solve it. It's appearing when the titles are too long, but its working with URLs normally as you see in the 2nd example as long the as the title is short enough.
It seems that symbols like "[]" beeing generated from something and the log is giving me 2x Overfull \hbox (X pt too wide) in paragraph.
setup: document.tex and bib/literature.bib
settings: pdfLatex (using biber and texindy)
Minimal example:
\documentclass[
11pt,
a4paper
]{scrreprt}
% add bibliography
\usepackage[style=alphabetic, sorting=anyt]{biblatex}
\addbibresource{bib/literature.bib}
\usepackage[colorlinks, urlcolor=blue]{hyperref}
\begin{document}
\cite{Gaedke}
\cite{IOT}
\printbibliography
\end{document}
literature.bib
#online{Gaedke,
author = {Gaedke, Martin and Heil, Andreas},
title = {{GET /dgs HTTP/1.1 Host: www.WebComposition.net.}},
url = {http://www.mendeley.com/research/dgs-http11-host-wwwwebcompositionnet/},
urldate={2018-08-19}
}
#online{IOT,
author = {Litzel, Nico },
title = {Was ist das Internet of Things?},
url = {https://www.bigdata-insider.de/was-ist-das-internet-of-things-a-590806/},
urldate={2018-08-19}
}
According to the biblatex documentation:
biburlnumpenalty: If this counter is set to a value greater than zero, biblatex will permit linebreaks after numbers in all strings formatted with the \url command from the url package. This will affect urls and dois in the bibliography. The breakpoints will be penalized by the value of this counter. If urls and/or dois in the bibliography run
into the margin, try setting this counter to a value greater than zero but less than
10000 (you normally want to use a high value like 9000). Setting the counter to zero
disables this feature. This is the default setting.
So, you can add:
\usepackage[style=alphabetic, sorting=anyt]{biblatex}
\addbibresource{bib/literature.bib
% If you want to break on URL numbers
\setcounter{biburlnumpenalty}{9000}
% If you want to break on URL lower case letters
\setcounter{biburllcpenalty}{9000}
% If you want to break on URL UPPER CASE letters
\setcounter{biburlucpenalty}{9000}
There are two separate issues:
The title, where LaTeX hyphenation does not know how to break www.WebComposition.net. You can do something here using \hyphenation{} in the preamble or see here for the many ways of hyphenation using the LaTeX packages for the German language
The URL, where LaTeX URL breaking (from the url package loaded by hyperref) does not know how to break wwwwebcompositionnet/. For this issue, refer to the answer by Eiji https://stackoverflow.com/a/53388858 or see https://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url/10419

Typesetting a large matrix in LaTeX

I have a 3x12 matrix I'd like to input into my LaTeX (with amsmath) document but LaTeX seems to choke when the matrix gets larger than 3x10:
\begin{equation}
\textbf{e} =
\begin{bmatrix}
1&1&1&1&0&0&0&0&-1&-1&-1&-1\\
1&-1&0&0&1&1&-1&-1&0&0&1&-1\\
0&0&1&-1&1&-1&1&-1&1&-1&0&0
\end{bmatrix}
\end{equation}
The error: Extra alignment tab has been changed to \cr. tells me that I have more & than the bmatrix environment can handle. Is there a proper way to handle this? It also seems that the alignment for 1's and the -1's are different, is that also expected of the bmatrix?
From the amsmath documentation (texdoc amsmath):
The amsmath package provides some
environments for matrices beyond the
basic array environment of LATEX. The
pmatrix, bmatrix, Bmatrix, vmatrix and
Vmatrix have (respectively) ( ), [
], { }, | |, and ∥
∥ delimiters built in. For naming
consistency there is a matrix
environment sans delimiters. This is
not entirely redundant with the array
environment; the matrix environments
all use more economical horizontal
spacing than the rather prodigal
spacing of the array environment.
Also, unlike the array environment,
you don’t have to give column
specifications for any of the matrix
environments; by default you can have
up to 10 centered columns. (If you
need left or right alignment in a
column or other special formats you
must resort to array.)
i.e. bmatrix defaults to a 10 column maximum.
A footnote adds
More precisely: The maximum number of
columns in a matrix is determined by
the counter MaxMatrixCols (normal
value = 10), which you can change if
necessary using LATEX’s \setcounter or
\addtocounter commands.
If you came to this page looking for the exact command (thanks to Scott Wales for the answer), you want this in your preamble:
\setcounter{MaxMatrixCols}{20}
Where you can replace 20 with the maximum number of columns you want.
The answer by Scott is correct, but I've since learned you can override the alignment. Taken from http://texblog.net/latex-archive/maths/matrix-align-left-right/
\makeatletter
\renewcommand*\env#matrix[1][c]{\hskip -\arraycolsep
\let\#ifnextchar\new#ifnextchar
\array{*\c#MaxMatrixCols #1}}
\makeatother
Now allows the command:
\begin{bmatrix}[r] ....
to have right-alignment!
Instead of a bmatrix you can use +bmatrix from the tabularray package:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\begin{document}
\begin{equation}
\textbf{e} =
\begin{+bmatrix}
1&1&1&1&0&0&0&0&-1&-1&-1&-1\\
1&-1&0&0&1&1&-1&-1&0&0&1&-1\\
0&0&1&-1&1&-1&1&-1&1&-1&0&0
\end{+bmatrix}
\end{equation}
\end{document}

Latex listings-package format option for uppercase keywords

I use the listings package to insert source code. I would like to print all keywords uppercase in the output, regardless of the case in the input.
The manual states that
keywordstyle=[number][*]style
produces just what I want. However the following (almost) minimal example does not work.
if I set keywordstyle to "[1][]{\bfseries}" I end up with "[]" in front of every keyword
and "[*]{\bfseries}" gives me an asterisk in the start of the document.
I also tried "\MakeUppercase" and "{\MakeUppercase}" for keywordstyle which resulted in several errors, the first being:
! Incomplete \iffalse; all text was ignored after line 11
Minimal example:
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{KA_assembler}
{morekeywords={add,and,or,xor},
keywordstyle=[1][*]{\bfseries},
sensitive=false,
}
\lstset{language=KA_assembler}
\begin{document}
\begin{lstlisting}
and %r1, %r2
xor %r2, %r3
and %r4, %r5
\end{lstlisting}
\end{document}
I use Miktex for compilation of the tex files. So how do I force uppercase for Keywords?
In the manual, the brackets around the * look a bit different then the brackets around number. The reason is that the brackets around * are not meant to be used in the latex code, they just indicate that the presence of the * is optional. So try
keywordstyle=[1]*\bfseries
or
keywordstyle=*\bfseries
- it worked for me.

Resources