Stop escape of latex math characters in Stata and estout - latex

The estout command in Stata will always escape underscores if a variable label has such a character. For example, running this after a simple regression and then
qui sum res, d
estadd scalar test = r(mean)
and outputting to a tex file:
esttab using "filename.tex", stats(r2 test, labels("\$R^2\$" "\$T_i\$")) se r2
star(* 0.10 ** 0.05 *** 0.01) label replace fragment nomtitles
coeflabels(_cons "$\alpha\$") nonumbers tex
will create a string $T\_i$ in the filename.tex output. Trying a label \$\beta=char(95)'{HML}\$` results in the same behavior. Apparently, the 'outreg2' command is smart enough to not escape this character if it sees it is in math mode, but estout did not inherit such behavior. Is there a smart way to stop the escape of the underscore?

To use latex characters such as the underscore, simply add the "substitute" option to the end of esttab. For underscores, your labels look like
label var "\$\beta_i\$"
so add
...substitute(\_ _)
to the 'estadd' command.

Related

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

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}

Formatting of Strings in Latex in whitespace insensitive environment / Z-Notation Schema

I'm using latex to model a few functions using Z-Notation, however, I'm having issues showing a string for output. In this reduced example code, the text in the quotes has a different formatting from what I would expect. What can I use to keep the formatting the text inside the quotes to be the same in the code snippet?
Edit: The overDraftMessage should be messageOutput, missed changing this when creating a reduced example.
\documentclass{article}
\usepackage{oz} % oz or z-eves or fuzz styles
\begin{document}
\begin{schema}{function}
messageOutput!: $STRING$ \\
\where
messageOutput! = ''Output looks strange.'' \\
\end{schema}
\end{document}
Solution from #lburski works, but tilde is not for this purpose. It should be used to make hard space (non-breaking space). To write space in whitespace insensitive environments, you need to escape it - write backslash before every space: ''Output\ looks\ strange''.
If you want a space between the words on your string ''Output looks strange.'' then try putting a tilde '~' between those words. So you string ends up being ''Output~looks~strange.''

GNUPlot+epslatex: Plotting labels froma datafile

I am using GNUPlot 4.7 on Windows with the epslatex terminal. Using latex commands in labels in single quotes works fine. Now I'd like to plot a datafile with a text column including latex commands using the labels plotting style in gnuplot:
data.txt
"\textalpha\n Ge" 0.6 1.05
"\textalpha\n Si" 1.09 0.7
"\ce{GaAs}" 1.43 1.05
Plotting command:
plot 'data.txt' u (column(2)):(column(3)):(column(1)) axes x2y1 w labels center offset 0,1 notitle
However, in the resulting tex file the backslashes and immediately following charakters are missing because they were parsed by GNUPlot. How can I make GNUPlot use the unchanged text within the quotes for its labels? I have tried with no success:
single quotes, both alone and nested within the double quotes
double backslashes
escaping the backslashes using $\ or $\\
using curly brackets within or instead of the double quotes
You need four backslashes to escape one: use "$\\\\alpha$" in your data file to get $\alpha$ in the tex file. Don't ask me why. Out of curiosity, you're plotting what against band gap?

How to simplify cos(pi)?

I'am new to Maxima and would like to use it for Denavit-Hartenberg matrices (consists of a lot of cos and sin terms). The problem is, that maxima does not simplify the following expression:
ex: x*cos(pi);
I expect, that Maxima simplifies ex to -x. How can this been done? (ratsimp(ex) and trigsimp(ex) have no effects)
In Maxima's dialect, the correct name of the constant is %pi. With it, it should simplify correctly.
As others have said, %pi is the correct name of the constant in Maxima. pi is simply rendered as π in GUIs like wxMaxima because all Greek letters are (you can have a variable named "π", which has nothing to do with the value of the constant π=3.14159...).
By the way, other predefined constants are written with the % character as well, such as for example
%e (=exp(1))
%i (=sqrt(-1))
%phi (the golden section)
The manual's index lists all % candidates.
Note that other useful constants that can not be expressed by digits, such as inf or false do not have the percent character.

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