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.

enter image description here

I want to populate the following lengths just once prior to entering the enumeration (or perhaps prior to entering the document environment) to free me from worrying whether or not the initialization has been invoked.

\newlength\EWD
\newlength\HWD
\newlength\HHWD

The initialization routine is given as follows,

\def\Init{%
    \settowidth{\EWD}{${}={}$}%
    \setlength{\HWD}{0.5\dimexpr\linewidth-\EWD\relax}%
    \setlength{\HHWD}{0.5\HWD}}

And the following is my real scenario.

enter image description here

\documentclass[twocolumn]{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}
\newlength\EWD
\newlength\HWD
\newlength\HHWD

\def\Init{%
    \settowidth{\EWD}{${}={}$}%
    \setlength{\HWD}{0.5\dimexpr\linewidth-\EWD\relax}%
    \setlength{\HHWD}{0.5\HWD}}

\def\TopLHS#1{\mathrlap{#1}\rule{\HWD}{0pt}}
\def\MiddleLHS#1{\rule{\HHWD}{0pt}\mathclap{#1}\rule{\HHWD}{0pt}}
\def\BottomLHS#1{\rule{\HWD}{0pt}\mathllap{#1}}

\begin{document}

\begin{enumerate}
\item\Init
$\!
\begin{aligned}[t]  
\TopLHS{\framebox[3cm]{Top LHS}}\\
\MiddleLHS{\framebox[3cm]{Middle LHS}}\\
\BottomLHS{\framebox[3cm]{Bottom LHS}}
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 1}\\
            \framebox[3cm]{Middle RHS 1}\\
            \framebox[3cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 2}\\
            \framebox[3cm]{Middle RHS 2}\\
            \framebox[3cm]{Bottom RHS 2}
        \end{multlined}
\end{aligned}
$
\end{enumerate}
\end{document}

Any suggestion is welcome!

share|improve this question
    
I don't understand: you want to avoid having to write \Init after \item? Then add \Init to the code of \item. –  egreg Apr 24 '13 at 19:41
    
@egreg: Yes. I don't want to write \Init for the first \item every time I start a new enumerate. In other words, I want to inject checking statement like \ifinitdefined plus invoking \Init if it is undefined to the first occurrence of item for each enumerate invocation. –  cyanide-based food Apr 25 '13 at 2:41

1 Answer 1

up vote 2 down vote accepted
+150

It's just a matter of adding \Init as the first duty of \item; other places don't guarantee that the parameters are correctly evaluated

\documentclass[twocolumn]{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}

\AtBeginDocument{%
  \expandafter\def\expandafter\item\expandafter{%
    \expandafter\Init\item}%
}



\newlength\EWD
\newlength\HWD
\newlength\HHWD

\def\Init{%
    \settowidth{\EWD}{${}={}$}%
    \setlength{\HWD}{0.5\dimexpr\linewidth-\EWD\relax}%
    \setlength{\HHWD}{0.5\HWD}}

\def\TopLHS#1{\mathrlap{#1}\rule{\HWD}{0pt}}
\def\MiddleLHS#1{\rule{\HHWD}{0pt}\mathclap{#1}\rule{\HHWD}{0pt}}
\def\BottomLHS#1{\rule{\HWD}{0pt}\mathllap{#1}}

\def\showInit{\texttt{EWD=\the\EWD; HWD=\the\HWD; HHWD=\the\HHWD}}

\begin{document}

\begin{enumerate}
\item
$\!
\begin{aligned}[t]  
\TopLHS{\framebox[3cm]{Top LHS}}\\
\MiddleLHS{\framebox[3cm]{Middle LHS}}\\
\BottomLHS{\framebox[3cm]{Bottom LHS}}
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 1}\\
            \framebox[3cm]{Middle RHS 1}\\
            \framebox[3cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 2}\\
            \framebox[3cm]{Middle RHS 2}\\
            \framebox[3cm]{Bottom RHS 2}
        \end{multlined}
\end{aligned}
$
\item\showInit
  \begin{itemize}
  \item\showInit
  \end{itemize}
\end{enumerate}
\end{document}

enter image description here

The \showItem macro is just to show the values of the parameters, which are different in the inner itemize as it should be.

share|improve this answer
    
Should it be better to do checking before entering the first item? –  cyanide-based food Apr 25 '13 at 8:50
    
@Bugbusters I stand corrected: not all the parameters are computed when before is evaluated. So there's not much hope other than adding \Init to \item, which was my original idea. –  egreg Apr 25 '13 at 9:01

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.