3

The Question

Can I use a TeX primitive in a "before" and "after" macro? (and how?)

There are two questions that I found useful and related to my question, which sent me in the right direction: how to even ask this question!

Example Situation

I am using a custom list setup with the enumitem package and I would like to use a primitive in the variables below:

\newlist{legal}{enumerate}{10}
\setlist[legal]{label*=\texttt{\arabic*.},resume,before={<HERE>}, after={<HERE>}}

I would like to put \vbox{ in the before={} and } in the after={}, but obviously I cannot type before={\vbox{}, after={}}

Why would I want to do this? For example, I could want to put a box around each mother and daughter list item, such that they remain on the same page. Or maybe I would like to put other primitives around my list environment just for kicks. Is there any way to do this?

  • 3
    I have a feeling this might be the usual x-y problem. I think it would be helpful if you actually posted what you are trying to achieve with the \vbox. – Peter Grill May 11 '14 at 20:11
  • @Peter Grill Alright, I added an example situation. I just want to know if there is a way to do this. I disagree with the x-y principle. Science does not need to be applied, rather can also be for the sake of knowing. See Gresham's Law (applied to science) and Vannevar Bush :) – Jonathan Komar May 11 '14 at 20:33
  • 1
    Why not before=\begin{minipage}{\textwidth}, after=\end{minipage}? – egreg May 11 '14 at 20:42
  • @egreg Because minipage is not a TeX primitive, it is an environment. – Jonathan Komar May 11 '14 at 20:44
  • @macmadness86 which of course is why you should use it as it is much less likely to break latex. You can use \vbox\bgroup and \egroup but they are not supported latex commands and things will go wrong if you do – David Carlisle May 11 '14 at 20:45
  • So what? Why should you use a primitive? However, the whole outer legal environment would be enclosed in the vertical box, so no page break would be available. – egreg May 11 '14 at 20:47
  • Thanks for looking at my question and trying to help me. You both are two of the most-skilled TeX gurus on the site. I would just like to know if it is possible, and if so, how I can do it. I have never seen it done, but it might prove useful someday for global changes e.g. \fbox{} around a list, or other things. A pure answer that addresses the question and not any particular problem would be great! – Jonathan Komar May 11 '14 at 20:48
  • @macmadness86 For adding a frame there are mdframed and tcolorbox. Trying to do it with low level tools is likely to break many things. – egreg May 11 '14 at 20:50
  • 5
    @macmadness86 I told you how to do it in my comment use vbox\bgroup not \vbox{ and similarly \egroup not } then you can put it in your macro arguments without messing up brace matching. But to put \fbox around a list you should not do that you should use the lrbox environment which was explicitly added to latex for that example. – David Carlisle May 11 '14 at 21:49
  • enumitem is already well "above" plain TeX, so I'm not sure what benefit there could possibly be from mixing in non-LaTeX code. If you want to go for a so-called "pure" solution, why not skip LaTeX all together and work in (e)plain TeX? Besides, lrbox is pretty low-level compared to enumitem.... – jon May 12 '14 at 02:43
  • @DavidCarlisle I cannot accept your answer as a comment, I am sure you know that. Thanks for your help! I would be happy to label this question as answered… – Jonathan Komar May 12 '14 at 11:50
  • @egreg Actually, there is a problem with page breaks with embedded lists. If you would like I can provide an example of this. And to everybody, I appreciate the warnings about doing this. Despite the potential problems, sometimes in a bind one must do what has to do to get the output to look right! – Jonathan Komar May 12 '14 at 11:54

1 Answers1

6

You can use

\vbox\bgroup

and

\egroup 

to start the box without using {} so you can pass these constructs in {} delimited arguments, but they are not supported latex commands and things will go wrong if you do.

But this should not be necessary for example to put \fbox around a list you should not do that you should use the lrbox environment which was explicitly added to latex for that example. (Or a package such as framed or mdframed)

David Carlisle
  • 757,742
  • Thanks! I will try to avoid using TeX primitives in higher-level LaTeX commands. Is it correct to assume that bgroup stands for begin group and egroup for end group? – Jonathan Komar May 16 '14 at 12:53