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.

I am using the \iteminput macro from the solution at How to adjust macro to respect current \linewidth? to import content from other TeX files. However, this appears to be effecting the indentation of text from \intertext{}. The red text below is where the problem is.

When using the normal \input things work great and the text is left aligned as desired, as shown in (a). However, when using the \iteminput macro the \intertext is shifted to the right, as shown in (b):

enter image description here

I found out that if I remove the \vtop{} from the \iteminput macro, I get the desired behavior. But since this is from an egreg solution, I am reluctant to do that without knowing if that will result in some other problem.

References:

Code:

\documentclass{article}
\usepackage{showframe}
\usepackage{xcolor}% to highlight the problem area in the output
\usepackage[fleqn]{amsmath}
\usepackage{enumitem}
\usepackage{filecontents}

\begin{filecontents*}{foo.tex}
    Two well known equations are:
    \begin{alignat*}{3}
        E & = mc^2 \\
        \intertext{\textcolor{red}{and}}
        F &= ma
    \end{alignat*}
\end{filecontents*}


\newcommand{\MyInput}[1]{%  
    \begingroup%           The grouping here is not currently causing a problem.
        \input{#1}%        But do need grouping here (for a unrelated reason).
    \endgroup%             
}%

% http://tex.stackexchange.com/questions/18247/how-to-adjust-macro-to-respect-current-linewidth/
\newcommand{\iteminput}[2][\topskip-1bp]{%
    \leavevmode%
    \vtop{%  Removing this fixs the problem.
        \hsize=\noexpand\linewidth\hrule height 0pt\kern-\dimexpr#1\relax%
        \MyInput{#2}%
    }%
}%

\begin{document}
\begin{enumerate}[label={(\alph*)}]
    \item \input{foo}            % This works great
    \item \iteminput[2.5ex]{foo} % This shifts "and" to right!!
\end{enumerate}
\end{document}
share|improve this question
    
\noexpand\linewidth looks distinctly odd (and wasn't in egreg's version) as \linewidth is not expandable. –  David Carlisle Jul 29 '12 at 23:46
    
@DavidCarlisle: Hmmm....Wonder where that came from? –  Peter Grill Jul 30 '12 at 4:36
add comment

1 Answer

up vote 12 down vote accepted

The problem is that already the initial solution is wrong and in this particular situation it shows. \vtop is not a LaTeX command, so if you use it you need to fully understand what it does and what it doesn't.

The important part is what it doesn't: it doesn't set up a new box-galley that ignores any outer circumstances like being inside an enumerate. So that fact is still visible inside and \intertext therefore assumes it has to indent its text. However the text is already indented for the simple reason that the whole box is. So a quick fix for your particular case only would be

\makeatletter
% http://tex.stackexchange.com/questions/18247/how-to-adjust-macro-to-respect-current-linewidth/
\newcommand{\iteminput}[2][\topskip-1bp]{%
    \leavevmode%
    \vtop{%  Removing this fixs the problem.
        \hsize=\noexpand\linewidth\hrule height 0pt\kern-\dimexpr#1\relax%
       \@totalleftmargin\z@   % cancel any line indentation
        \MyInput{#2}%
    }%
}%
\makeatother

But for course this is not right either as we can see from looking at \@arrayparboxrestore to see what LaTeX is really resetting in such a case.

Bottom line, for a general solution, you are much better off to use a minipage environment (which would take care of all this as it is made to work with other LaTeX constructs). Alternatively you really have to work a lot harder to blend your command with the internals of LaTeX.

share|improve this answer
add comment

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.