Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\documentclass{scrreprt}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\usepackage{graphicx}

\usepackage{polyglossia}
\setdefaultlanguage[babelshorthands=true]{german}

% align in enumerate
\newenvironment{enumalign}[1][\textwidth]%
{\item \begin{minipage}[t]{#1} \vspace{-5.375ex} \begin{align*}}
{\end{align*} \end{minipage}}

\renewcommand*\thechapter{\arabic{chapter}}

\usepackage{color}

\newcommand*\defin[1]{\textcolor{red}{#1}}

\begin{document}

\begin{enumerate}
\begin{enumalign}
test
\end{enumalign}
\end{enumerate}

\end{document}

LaTeX is telling me \begin{align*} on input line 511 ended by \end{enumalign}. It seems to have something to do with how LaTeX interprets my code and replaces macros - but I could not get it right.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

This is the correct code:

\documentclass{scrreprt}

\usepackage{amsmath}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\usepackage{graphicx}

\usepackage{polyglossia}
\setdefaultlanguage[babelshorthands=true]{german}

% align in enumerate
\makeatletter
\newenvironment{enumalign}[1][\linewidth]%
{\item\minipage[t]{#1}\vspace{-5.375ex}\start@align\@ne\st@rredtrue\m@ne}
{\endalign\endminipage}
\makeatother

\renewcommand*\thechapter{\arabic{chapter}}

\usepackage{color}

\newcommand*\defin[1]{\textcolor{red}{#1}}

\begin{document}

\begin{enumerate}
\begin{enumalign}
test
\end{enumalign}
\end{enumerate}

\end{document} 

Output:

enter image description here

First of all, you have to load amsmath if you want to use align* in your document.

Moreover, the available room for the minipage is \linewidth and not \textwidth, so I changed it.

And now, try to see why you've got that error. Nested environments often cause errors like the one you've got. To circumvent this, you have to use command-form of the environment (begin and end).

For example, the command form of the environment myenv are

\myenv     % same as \begin{myenv}
\endmyenv  % same as \end{myenv}

In your case, I've substituted \begin{minipage} with \minipage and \end{minipage} with \endminipage.

About align* (being it the starred form), if you take a look at the definition of the align* environment in amsmath.sty, you'll see

\newenvironment{align*}{%
  \start@align\@ne\st@rredtrue\m@ne
}{%
  \endalign
}

so, I've substituted \begin{align*} with \start@align\@ne\st@rredtrue\m@ne and \end{align*} with \endalign.

Note that, as egreg points out in his comment, you can replace \start@align\@ne\st@rredtrue\m@ne with \@nameuse{align*}, which is a wrapper for \csname align*\endcsname.

share|improve this answer
1  
Or just \@nameuse{align*} instead of \start@align\@ne\st@rredtrue\m@ne –  egreg Dec 28 '13 at 14:08
    
@egreg Right. I've just taken the definition from amsmath.sty. I'll add it in the answer. –  karlkoeller Dec 28 '13 at 14:13
    
It works and I do see roughly where this is going. An explanation would still be very nice. –  chaosflaws Dec 28 '13 at 14:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.