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'm having issues with text going past the end of the specified \textwidth. I posted this question about why text was being placed beyond the specified line width. The MWE provided there produced situations similar to mine. Adding \sloppy fixed all the problems posted in that MWE, but when I used that in my larger document, it had absolutely no effect on the output.

Narrowing my problem down further, I see that the problem stems from the \iteminput macro which is a solution provided to an issue related to the alignment of item number in a list containing a minipage that was originating in a standalone file. I have been using this to input my files. This macro was necessitated by the fact that the imported standlalone files were not being aligned within enumerated lists.

It appears that \iteminput is ignoring that fact that the \linewidth has modified since it is now within an enumerate list. So, my question is: How do I adjust the \iteminput macro to respect the current \linewidth.

The MWE for this requires two files. The first file here is the standalone file called Item-from-File.tex:

\documentclass[preview=false]{standalone}
\usepackage{standalone}
\usepackage{paralist}

% geometry settings identical to main file.
\usepackage{geometry}
\geometry{top=0.5in}
\geometry{bottom=0.5in}
\geometry{paperheight=11.0in}
\geometry{paperwidth=8.5in}
\geometry{textwidth=6.0in}
\geometry{left=1.125in}
\geometry{right=1.125in}
\geometry{showframe=true}

\begin{document}
  Here is a line of text, but one that is from a separate standalone file.
  This file typeset by itself is fine. When this is input into an enumerated list 
  via the normal input macro, things are also fine. But the text goes past the end
  of the line if input with modified input macros.
  %
  % Updated to include following:
  \begin{enumerate}[(a)]
     \item First item: If this sentence is long enough things are not so good when 
           this is included in another file. But things are fine in this standalone 
           file.
     \begin{enumerate}[(i)]
       \item First sub-item: If this sentence is long enough things are not so good 
             when this included in another file. But things are fine in this 
             standalone file.
     \end{enumerate}
  \end{enumerate}
\end{document}

The second is the main document:

\documentclass{article}
\usepackage{standalone} % Needed for the standalone file
\usepackage{paralist}

% geometry settings identical to standalone file.
\usepackage{geometry}
\geometry{top=0.5in}
\geometry{bottom=0.5in}
\geometry{paperheight=11.0in}
\geometry{paperwidth=8.5in}
\geometry{textwidth=6.0in}
\geometry{left=1.125in}
\geometry{right=1.125in}
\geometry{showframe=true}

\newcommand{\iteminput}[2][\topskip-1bp]{%
  \leavevmode\vtop{\hrule height 0pt\kern-\dimexpr#1\relax
    \input{#2}}}


\begin{document}
Text in this file, things work great:
\begin{enumerate}
  \item When this text appears in the same file things are ok.
        The line goes to the end of the correct spot on the page and wraps around.
  \item \input{Item-from-File.tex}% This is ok
  \item \iteminput[2.5ex]{Item-from-File.tex}% This is a problem
\end{enumerate}
\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Just pass the desired line width to the macro.

\newcommand{\iteminput}[2][\topskip-1bp]{%
  \leavevmode\vtop{
    \hsize=\linewidth\hrule height 0pt\kern-\dimexpr#1\relax
    \input{#2}}}

As Frank Mittelbach points out in another answer, adding \@totalleftmargin=0pt is necessary for avoiding bad indentation (the outer one is kept inside):

\makeatletter
\newcommand{\iteminput}[2][\topskip-1bp]{%
  \leavevmode\vtop{
    \hsize=\linewidth\hrule height 0pt\kern-\dimexpr#1\relax
    \@totalleftmargin=\z@
    \input{#2}}}
\makeatother
share|improve this answer
    
Is there a simple way to modify this so that the evaluation of \linewidth is deferred? I have updated the example to show the problem when there is an enumerated list in the input file. –  Peter Grill May 17 '11 at 4:18
    
@Peter: I get an error even without the \iteminput line. –  egreg May 17 '11 at 6:49
    
List item 2 in this image uses just \input and it seems to work fine: –  Peter Grill May 17 '11 at 7:23
    
@Peter: There's something about paralist that I don't understand. If I don't load it in the main file, the enumerate in the input file gives an error. –  egreg May 17 '11 at 7:38
    
I thought paralist was requried for the enumerate environment? It is needed in both files. I posted a related question: what are the differences between using paralist vs enumitem –  Peter Grill May 17 '11 at 7:47

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.