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?

  • 2
    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
  • 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
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)

| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.