Mixing text and equations in latex

Viewed 34

I am working on some algorithm documenation for a project and trying to write out the equations in latex.

The one problem I am encountering and have not found a nice way (assuming there is one) is mixing text and equations in a single line.

Here is an example of what I am doing (and later how I am doing it).

I am defining the equation, and than what each variable means (left aligned text hence the &). enter image description here

The latex code to generate this

\begin{equation}
A = 3B * 4C + 5D
\end{equation}
Where:
\begin{flalign*} 
    &A = Something \: cool\\
    &B = Something \: cooler\\
    &C = Something \: even \: cooler!!\\
\end{flalign*} 

My questions are:

  1. Is there a better way to do spaces in between words besides putting \: everywhere? If I dont put the \: I get this below, all the words are combined? enter image description here

  2. Is this the most latex idiomatic way to acheive this? Am I missing something that could help me?

So I can get the output the way I want, I just want to make sure its "correct" before I get to deep.

1 Answers

You should never set whole words in math mode. Besides the obvious problem with spaces you noticed, this will also completely mess up the kerning between the letters.

Instead you can use the \text{...} macro from the amsmath package.


The amsmath package also provides the \intertext macro, which you could use to insert Where: while retaining alignment of the equal signs in the equations above and below:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{flalign} 
    A &= 3B \cdot 4C + 5D\\
  \intertext{Where:}
    A &= \text{Something  cool}\notag\\
    B &= \text{Something  cooler}\notag\\
    C &= \text{Something even  cooler!!}\notag
\end{flalign} 

\end{document}

enter image description here

Related