1

I'm using the document class article and I would like to know if there is an easy way to write aligned equations with all letters automatically uprighted.

Since my equations contain lot of letters, I should use \text each time.

Looking for it I found All letters upright in math mode (equivalent to \rm) which suggests to use the \mathrm command. Unfortunately it does not seem to work when it contains the & symbol (which is needed in order to align the equations).

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{physics}

\begin{document}

\begin{align*}
    \mathrm{TDD &= \frac{18}{9} = 2'}\\
    \mathrm{TF &= TI-TDD = 25-2 = 23'}\\
    \text{TR} &= \frac{18-5}{9} = 2'\\
    \text{TT} &= \text{TI}+\text{TRT}+\text{TD}+\text{TRS} = 25+2+5+1 = 33'
\end{align*}

\end{document}

enter image description here

  • 1
    the normal way would be to write \mathrm{TDD} although it is possible to change the default (probably an answer on site already I'll look... – David Carlisle Feb 8 at 14:11
  • 1
    I would use \mathrm{TR} and \mathrm{TDD} (not \text) but you could do this, replacing \mathtt by \mathrm tex.stackexchange.com/a/63000/1090 – David Carlisle Feb 8 at 14:15
  • Thank you! We are in the right direction, there is still a little problem in the visualization since two different fonts are used (one before the & sign, another one after it). Look here i.imgur.com/hqF3sLJ.png – sound wave Feb 8 at 14:23
  • 1
    No you forced a default of mathtt !! as I said you need that answer but using mathrm instead, also you need to remove all uses of \text and of course fix the brackets in any remaning \mathrm just to be around each identifier not spanning &) If you get an error such as ! Missing } inserted. do not even look at the pdf output, it is just a possible debugging aid, tex makes no attempt at making sensible typeset output after an error. – David Carlisle Feb 8 at 14:28
  • 1
    that sounds like an unrelated error, hard to guess what you did wrong, but align should never be in math mode so I don't see how you could get that error or have formulas before the alignment? The code in my answer generates no error. – David Carlisle Feb 8 at 14:41
3

You can not have & inside {} it is not really \mathrm that is causing the error.

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{physics}

\begin{document}

Normal way
\begin{align*}
    \mathrm{TDD} &= \frac{18}{9} = 2'\\
    \mathrm{TF} &= \mathrm{TI}-\mathrm{TDD} = 25-2 = 23'\\
    \mathrm{TR} &= \frac{18-5}{9} = 2'\\
    \mathrm{TT} &= \mathrm{TI}+\mathrm{TRT}+\mathrm{TD}+\mathrm{TRS} = 25+2+5+1 = 33'
\end{align*}

I wouldn't do this
 \everymath{\mathrm{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}
\begin{align*}
    TDD &= \frac{18}{9} = 2'\\
    TF &= TI-TDD = 25-2 = 23'\\
    TR &= \frac{18-5}{9} = 2'\\
    TT &= TI+TRT+TD+TRS = 25+2+5+1 = 33'
\end{align*}


\end{document}
  • Thank you very much, this solve all my problems! Why wouldn't you do that? – sound wave Feb 8 at 14:46
  • @soundwave because the fist form is much clearer especially if you alias \mathrm to something semantically relevant in your context such as \newcommand\var{\mathrm} ... \var{TR} ..... and poking changes into the latex setup to change the defaults will work in your document but mean you can not share those fragments in a mathjax website or some journal document class where changing the default styling would not be allowed or would break other code – David Carlisle Feb 8 at 14:55
  • You are right, but since this document I am working on it is only for personal use, it is good. – sound wave Feb 8 at 15:05
  • Anyway, the error I wrote before, is due to the command \everydisplay{\mathrm{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}} which do the same work as the other one, but in the framework \[...\]. – sound wave Feb 8 at 15:07
  • @soundwave ah, yes, it would do that:-) – David Carlisle Feb 8 at 15:21
1

A literal answer to your question is the [math-style=upright] package option of unicode-math, which you can switch on and off with the commands

\unimathsetup{math-style=upright}

\unimathsetup{math-style=ISO}

For example:

\documentclass[varwidth=10cm, preview]{standalone}
\usepackage{physics}
\usepackage[math-style=upright]{unicode-math}

\begin{document}

\begin{align*}
    TDD &= \frac{18}{9} = 2' \\
    TF &= TI-TDD = 25-2 = 23' \\
    TR &= \frac{18-5}{9} = 2' \\
    TT &= TI+TRT+TD+TRS = 25+2+5+1 = 33'
\end{align*}

\end{document}

Physics equation sample

That said, I wouldn’t recommend you use this technique. (Although I do recommend that you use unicode-math if you’re allowed to!) The \mathrm solution is still supported and will work fine.

I personally find it handy to declare something like \newcommand\TDD{\ensuremath{\mathop{\mathrm{TDD}}}} and then write \TDD in the equations. If you might for some reason want to write x \TDD or \TDD \TI instead of x \cdot \TDD and \TDD \cdot \TI, the \mathop makes x TDD TI behave like log log x (that is, typeset like an operator name).

\documentclass[varwidth=10cm, preview]{standalone}
\usepackage[T1]{fontenc}
\usepackage{physics}

\newcommand\upvar[1]{\ensuremath{\mathop{\mathrm{#1}}}}
\newcommand\TD{\upvar{TD}}
\newcommand\TDD{\upvar{TDD}}
\newcommand\TF{\upvar{TF}}
\newcommand\TI{\upvar{TI}}
\newcommand\TR{\upvar{TR}}
\newcommand\TRS{\upvar{TRS}}
\newcommand\TRT{\upvar{TRT}}
\newcommand\TT{\upvar{TT}}

\begin{document}

\begin{align*}
    \TDD &= \frac{18}{9} = 2' \\
    \TF &= \TI-\TDD = 25-2 = 23' \\
    \TR &= \frac{18-5}{9} = 2' \\
    \TT &= \TI+\TRT+\TD+\TRS = 25+2+5+1 = 33'
\end{align*}

\end{document}

This is just like typing \log or \sin. An existing shorthand for this is \operatorname{TDD} from amsmath.

This site is temporarily in read only mode and not accepting new answers.

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