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.

Please how do I stop at all cost in the following? Note: \leavevmode is no rescue.

\documentclass[crop]{standalone}
\def\z#1#2{%
  \ifnum#1<\numexpr#2+1\relax
    \noindent\hfill#1%
    \ifnum#1=#2\relax
      \hfill\null\endgraf
    \else
      \ifdefined\xz
        \hfill\number\numexpr#1+1\hfill\null\endgraf
      \else
        \let\xz\relax\hfill\null\endgraf
      \fi
    \fi
    \expandafter\z\expandafter{\number\numexpr#1+2\expandafter}%
    \expandafter{\number#2\expandafter}%
  \fi
}
\begin{document}
\z19
\stop
\end{document} 

enter image description here

share|improve this question
    
The output image you've attached appears to be produced only if \documentclass{article} is used, but not if \documentclass[crop]{standalone} is in effect. Am I missing something? –  Mico Jul 7 '12 at 2:31
    
Could you say a little more what you mean by "stop at all costs"? It seems that the loop terminates, at least; do you mean you want to stop executing in the middle of the loop? –  Ryan Reich Jul 7 '12 at 4:01
1  
With the MWE as written, you get ! Missing } inserted. as the error: replace the crop option by preview to get ! You can't use `\end' in internal vertical mode., which relates more to the title. –  Joseph Wright Jul 7 '12 at 6:36
    
@Mico: Joseph Wright has answered the question. I didn't look in standalone.sty to see the boxing that it does. Ditto Ryan Reich. –  Ahmed Musa Jul 8 '12 at 2:10
add comment

1 Answer

up vote 6 down vote accepted

With the standard settings, standalone class uses an \hbox to work. You can see this if you add

\showthe\currentgrouplevel
\showthe\currentgrouptype

before \stop: the reported values are group level 1 and group type 2 ('hbox group'). You simply cannot use the \end primitive inside a box and expect all to be well. Moreover, even if you test for a box using the e-TeX extensions, closing it does not help as the content then disappears as you get no output. So with a complex set up such as the standalone class you really do have to 'stick to the rules' in terms of interface, or write everything yourself.

share|improve this answer
    
Do you think the scheme at tex.stackexchange.com/questions/56294/… can help? –  Ahmed Musa Jul 8 '12 at 2:15
    
@AhmedMusa Possibly, but if there is more than once group level then life gets extremely complicated. In that case, you'll need to insert code which will then check again on the group type, and insert \stop only when you are 'safe'. –  Joseph Wright Jul 8 '12 at 8:15
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.