21

Motivation

When I use math mode inside of itemize environments for multiline equations, I have to do something like the following

...
\begin{itemize}
  \item $\begin{aligned}[t]
    equation stuff
  \end{aligned}$
  ...
\end{itemize}
...

Question

How can I wrap the two components $\begin{aligned}[t] and \end{aligned}$ into a new symbol, e.g. §? I'd like to write the above example as

...
\begin{itemize}
  \item §equation stuff§
  ...
\end{itemize}
...

It is favorable for the solution to be robust.


(It is not required for the new symbol to be §.)

4
  • 1
    How about a macro \mleq defined as \newcommand\mleq[1]{$\begin{aligned}[t] #1 \end{aligned}$?
    – Herr K.
    Aug 21, 2013 at 15:19
  • @Qrrbrbirlbel Is it then not recommended to use aligned? What do you propose instead? Aug 23, 2013 at 13:51
  • @HenriMenke No. I don’t know of a better alternative (except maybe an array solution). As you can see in the numerous linked references you will just to insert a \!. Aug 24, 2013 at 5:14

3 Answers 3

22

The \catcode`§=\active method won't work if the document declares

\usepackage[utf8]{inputenc}

because § is a two byte character in UTF-8. For this case you can use

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

\usepackage{newunicodechar}
\newunicodechar{§}{\mymath}
\def\mymath#1§{$\begin{aligned}[t] #1\end{aligned}$}

\newenvironment{itemalign}
  {$\aligned[t]}
  {\endaligned$}

\begin{document}
\begin{itemize}
\item §x&=2\\y&=6§
\item \begin{itemalign}x&=2\\y&=6\end{itemalign}
\end{itemize}
\end{document}

that has the advantage of working also with LuaLaTeX and XeLaTeX (where the call to inputenc should not be present).

However, I'd recommend using the new environment method.

enter image description here

4
  • You used \aligned to open the envorinment, but you used \endalignedat to close it (Note the trailing at). Anyway it works, but why? And why don't you use \endaligned? Aug 23, 2013 at 19:26
  • 1
    @HenriMenke Thanks for noting! I checked and discovered that \endalignedat executes \endalign. ;-) But it's wrong anyway.
    – egreg
    Aug 23, 2013 at 19:40
  • I used the \newenvironment solution. To make it more align-like I'd like to add a new line at the end of itemalign. I used {\endaligned$\par}, but I doubt, that this is the right procedure, because this will start a new paragaph after each itemalign. What do I have to insert instead of \par? Aug 28, 2013 at 20:56
  • @HenriMenke I believe this should be the entire item, so you need nothing after it.
    – egreg
    Aug 28, 2013 at 21:04
5

If I were you, I would use two different macros to open and close the environment. I would do something like

\def\ba#1\ea{$\begin{aligned}[t]#1\end{aligned}$}

that can be use like that

\begin{itemize}
\item \ba equation stuff \ea
\end{itemize}
5

How about making § active?

\documentclass{article}

\usepackage{amsmath}

\catcode`§=\active
\def§#1§{$\begin{aligned}[t] #1\end{aligned}$}

\begin{document}
\begin{itemize}
\item §x&=2\\y&=6§
\end{itemize}
\end{document}

Then we can scan an argument up to the next occurence of § and wrap this in aligned.


As @egreg pointed out, this will be problematic using pdflatex and inputenc (see also: Catcodes of unicode characters with \usepackage[utf8]{inputenc}). A simple workaround in this case is changing § to e.g. |.

2
  • This would not work with \usepackage[utf8]{inputenc}
    – egreg
    Aug 21, 2013 at 15:44
  • @egreg fair point! It works with my xelatex, however, so I didn't notice. Changing the character from § to e.g. | fixes that though.
    – Jonathan
    Aug 21, 2013 at 16:22

You must log in to answer this question.

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