How do I add notes to the side of my equations?

  • Context: LaTeX 
  • Thread starter Thread starter Eclair_de_XII
  • Start date Start date
  • Tags Tags
    Notes
Click For Summary

Discussion Overview

The discussion revolves around formatting mathematical equations in LaTeX, specifically how to add notes or comments alongside equations and how to color specific columns in matrices. Participants explore various environments and methods for achieving these formatting goals.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant suggests using a table to place equations in one column and comments in another, expressing surprise at the feasibility of this approach.
  • Another participant proposes using the align environment from AMSLaTeX to include comments next to equations, providing an example of its use.
  • There is discussion about the syntax for coloring columns in matrices, with one participant noting that using the array environment may yield better visual results than the pmatrix environment.
  • Some participants express confusion about the necessity of defining macros for variables, questioning whether it saves time compared to typing them directly.
  • One participant mentions the need to adjust page margins if long comments are included, suggesting that comments should be kept concise.
  • Another participant shares code snippets for coloring rows, columns, and cells in matrices, highlighting how to implement these features in LaTeX.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method for adding comments to equations or the necessity of using macros, indicating that multiple competing views remain on these topics.

Contextual Notes

Limitations include potential issues with page layout when adding lengthy comments, and the discussion does not resolve the effectiveness of different environments for formatting equations.

Eclair_de_XII
Messages
1,082
Reaction score
91
TL;DR
Let's say I wanted to write out a calculation that required some steps that I wanted to write out on the right-side of each equation in an align environment. How would I accomplish this?
Let's say I wanted to describe the first step of this calculation by writing "Factor out ##c_2c_3,c_3,c_3## from these determinant expansions." on the right side of the second expression on the right. Which environment would work well?

Untitled.png
Below is the code generating the text in the image above.

[CODE highlight="24"]\documentclass{article}

\usepackage{mathtools}

\newcommand{\sn}[1]{s_#1}
\newcommand{\cs}[1]{c_#1}

\begin{document}

\begin{align*}
r^{-3}\det[c'] &=&% First line.
-\sn{3} \det
\begin{pmatrix}
-\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} & -\cs{1} \cs{2} \sn{3} \\
\cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} & -\sn{1} \cs{2} \sn{3} \\
0 & \cs{2} \cs{3} & -\sn{2} \sn{3}
\end{pmatrix}
\\[6pt]&+&
\cs{3} \det
\begin{pmatrix}
\cs{1} \cs{2} \cs{3} & -\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} \\
\sn{1} \cs{2} \cs{3} & \cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} \\
\sn{2} \cs{3} & 0 & \cs{2} \cs{3}
\end{pmatrix}\\[6pt]&=&% Second line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^4 \det
\begin{pmatrix}
\cs{1} \cs{2} & -\sn{1} & -\cs{1} \sn{2} \\
\sn{1} \cs{2} & \cs{1} & -\sn{1} \sn{2} \\
\sn{2} & 0 & \cs{2}
\end{pmatrix}\\[6pt]&=&% Third line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&=&% Fourth line.
\cs{2} \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}
\end{align*}

\end{document}[/CODE]

Also, I want to color some of these columns. I found an article relating to this, but I am most confused about the syntax, and how to implement it into my code.

https://tex.stackexchange.com/questions/69713/matrix-change-row-or-column-background
 
Last edited:
Physics news on Phys.org
Have you tried a table? You could have one column for your equations and another for your comments.
 
Huh, I had not thought it possible to make a table consisting of mathematical equations on one side and text on the other.
 
Eclair_de_XII said:
Let's say I wanted to describe the first step of this calculation by writing "Factor out c2c3,c3,c3c2c3,c3,c3c_2c_3,c_3,c_3 from these determinant expansions." on the right side of the second expression on the right. Which environment would work well?
Before ending a line with \\, you have to append
&& \text{Factor out } \cs{2}\cs{3}, \ \cs{3}, \ \cs{3} \ \text{from these determinant expansions}. Your new code would look like this:
[CODE highlight="24"]\documentclass{article}

\usepackage{mathtools}

\newcommand{\sn}[1]{s_#1}
\newcommand{\cs}[1]{c_#1}

\begin{document}

\begin{align*}
r^{-3}\det[c'] &=&% First line.
-\sn{3} \det
\begin{pmatrix}
-\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} & -\cs{1} \cs{2} \sn{3} \\
\cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} & -\sn{1} \cs{2} \sn{3} \\
0 & \cs{2} \cs{3} & -\sn{2} \sn{3}
\end{pmatrix}
\\[6pt]&+&
\cs{3} \det
\begin{pmatrix}
\cs{1} \cs{2} \cs{3} & -\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} \\
\sn{1} \cs{2} \cs{3} & \cs{1} \cs{2} \cs{3} & -\sn{1} \sn{2} \cs{3} \\
\sn{2} \cs{3} & 0 & \cs{2} \cs{3}
\end{pmatrix} && \text{Factor out } \cs{2}\cs{3}, \ \cs{3}, \ \cs{3} \ \text{from these determinant expansions}
\\[6pt]&=&% Second line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^4 \det
\begin{pmatrix}
\cs{1} \cs{2} & -\sn{1} & -\cs{1} \sn{2} \\
\sn{1} \cs{2} & \cs{1} & -\sn{1} \sn{2} \\
\sn{2} & 0 & \cs{2}
\end{pmatrix}\\[6pt]&=&% Third line.
\cs{2} \sn{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&+&
\cs{2} \cs{3}^2 \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}\\[6pt]&=&% Fourth line.
\cs{2} \cs{3}^2 \det
\begin{pmatrix}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{pmatrix}
\end{align*}

\end{document}[/CODE]
(Hope that I placed it at the correct position.)

Note that if you include long comments to equations, you will have to change your page margins. Otherwise, the text will go out of page. Better keep the comments short and simple.

Also have a look at the following:
https://tex.stackexchange.com/questions/147592/to-have-nice-tabbed-text-next-to-equations

https://tex.stackexchange.com/questions/47687/adding-line-by-line-comments-to-math-proofs

Edit: Corrected typo.
 
Last edited:
  • Like
Likes   Reactions: Eclair_de_XII
Eclair_de_XII said:
Also, I want to color some of these columns.
This can be done in pmatrix environment, but it doesn't look impressive. The row color overlaps with the brackets:

1587711108074.png


If you use the array environment, it looks better:

1587711148075.png


You need to import the xcolor package.

The code would look something like this:
[CODE title="Using color in table row and column" highlight="3,7,15,17,23"]\documentclass{article}
\usepackage{mathtools}
\usepackage
{xcolor}

\newcommand{\sn}[1]{s_#1}
\newcommand{\cs}[1]{c_#1}
\newcolumntype{a}{>{\columncolor{red}}c}

\begin{document}

\begin{align*}
r^{-3}\det[c'] &=
-\sn{3} \det
\left(\begin{array}{ccc}
\rowcolor{red!20}
-\sn{1} \cs{2} \cs{3} & -\cs{1} \sn{2} \cs{3} & -\cs{1} \cs{2} \sn{3} \\
\cs{1} \cs{2} \cs{3} & \cellcolor{green!30} -\sn{1} \sn{2} \cs{3} & -\sn{1} \cs{2} \sn{3} \\
\rowcolor{yellow!50}
0 & \cs{2} \cs{3} & -\sn{2} \sn{3}
\end{array}\right)\\
&= 3\\
&= \cs{2} \sn{3}^2 \cs{3}^2 \ \det
\left(\begin{array}{>{\columncolor{blue!30}}cca}
-\sn{1} & -\cs{1} \sn{2} & \cs{1} \cs{2} \\
\cs{1} & -\sn{1} \sn{2} & \sn{1} \cs{2} \\
0 & \cs{2} & \sn{2}
\end{array}\right)
\end{align*}

\end{document}[/CODE]
The above code would generate:

1587714142798.png


To summarise, if you place \rowcolor{red!20} before a row, that row will get coloured. If you want to colour a column, place >{\columncolor{blue!30}} before the column letter in the declaration of array. If you want to colour only a cell, use \cellcolor{green!10} at the beginning of the cell. You can also define a new column type so as to avoid clutter.

See the highlighted lines in the above code.

Feel free to ask questions if anything is not clear.
 
Last edited:
  • Like
Likes   Reactions: Eclair_de_XII
Eclair_de_XII said:
Huh, I had not thought it possible to make a table consisting of mathematical equations on one side and text on the other.
You might be right. I've never tried it.
 
You can use the align environment from AMSLaTeX

$$
\begin{align*}
E &= mc^2 & \text{Einstein} \\
i \hbar \frac{\partial}{\partial t} \psi &= \hat{H} \psi & \text{Schrödinger}
\end{align*}
$$

Code:
\begin{align*}
E &= mc^2  & \text{Einstein} \\
i \hbar \frac{\partial}{\partial t} \psi &= \hat{H} \psi & \text{Schrödinger}
\end{align*}

By the way, I don't understand why you define \sn and \cs. It takes fewer keystrokes to type c_1 than \cs{1}.
 
DrClaude said:
By the way, I don't understand why you define \sn and \cs. It takes fewer keystrokes to type c_1 than \cs{1}.

I see your point; the latter string would take twice as many keystrokes to type as the former, depending on if holding the shift key can be counted as a keystroke. I guess I just got too caught up in writing macros that I had neglected to consider the fact that they're ideally used in order to save time and keystrokes.
 
I forgot to do something yesterday. I'm not sure if simply up-voting a post would convey a message of thanks properly.

Wrichik Basu said:
Before ending a line with \\, you have to append
&& \text{Factor out } \cs{2}\cs{3}, \ \cs{3}, \ \cs{3} \ \text{from these determinant expansions}.

Thank you for the information as well as the links. I shall keep them on hand should I decide to write amateur textbook-style explanations again.

Wrichik Basu said:
To summarise, if you place \rowcolor{red!20} before a row, that row will get coloured. If you want to colour a column, place >{\columncolor{blue!30}} before the column letter in the declaration of array. If you want to colour only a cell, use \cellcolor{green!10} at the beginning of the cell. You can also define a new column type so as to avoid clutter.

Thank you for the clarification. I am grateful for someone translating LaTeX for me. It's much more satisfying learning the syntax and the like, rather than searching for similar code on the world-wide web and copy-pasting it into my own document.
 
  • Like
Likes   Reactions: Wrichik Basu

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
4K