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'd like to have a savebox (or savebox-like functionality) that contains some 'simple' formatting, for example lists.

\documentclass{article}
\begin{document}
  This is a sentence
  \begin{itemize}
    \item I am a list
  \end{itemize}
\end{document}

However my experimenting with \savebox, \sbox, \begin{savebox} and the like are failing me. I also tried to define a minipage inside the savebox, but either that doesn't work or I don't know the syntax.

share|improve this question
    
Welcome to TeX.SX! \newcommand{\reptext}{This ...} and then \reptext when you need it. –  egreg Apr 3 at 12:23

2 Answers 2

up vote 5 down vote accepted

For this type of material you can just save your text etc. in a macro

Sample output

\documentclass{article}

\begin{document}

\newcommand{\mytext}{This is a sentence
\begin{itemize}
\item I am a list
\end{itemize}}

\mytext

Something else.

\mytext

\end{document}
share|improve this answer

While Andrew's solution works great in many, many situations, it will fail in some, for example, if you try to place \mytext in an \fbox. To get around that problem, you really have to define \mytext to place the contents in a box.

\documentclass{article}
\parindent 0in
\begin{document}

\newcommand{\mytext}{\setbox0=\vbox{%
This is a sentence
\begin{itemize}
\item I am a list
\end{itemize}%
}\box0}

\mytext

Something else.

{\hfill\makebox[0pt]{\fbox{\mytext}}\hfill}

\noindent\rule{\textwidth}{1pt}

\end{document}

enter image description here

share|improve this answer
    
Do you think that \fbox{\begin{itemize}...\end{itemize}} is legal? I bet you don't. So what? Of course you get an overfull message with your code and adding \noindent won't help. –  egreg Apr 3 at 13:42
    
@egreg I was just trying to make the more general point that there are some things that actually have to get stuffed into a box if you are going to later manipulate them. Perhaps this was not the best example on which to make that point. –  Steven B. Segletes Apr 3 at 15:58
    
@egreg Revised my MWE to better make the point. –  Steven B. Segletes Apr 3 at 16:04

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.