0

I would like to execute a command which produces text, but not have that text visible anywhere inside the document. Can we put the command inside a box, which clips other text, such as in the middle of the page? Normally, this would look ugly (a box text rendered on top of other text). Can we make the text invisible? That is, have a box smack dab in the middle of the page full of invisible text? Or what if we place the box of text outside of the page margins. That way, the text will be there, but not visible?

IdleCustard
  • 1,194

1 Answers1

0

The following appears to work:

\documentclass{minimal}
\usepackage[pscoord]{eso-pic}
\newcommand{\placetextbox}[3]{
\setbox0=\hbox{#3}
\AddToShipoutPictureFG*{
\put(\LenToUnit{#1\paperwidth},\LenToUnit{#2\paperheight}){\vtop{{\null}\makebox[0pt][c]{#3}}}%
}
}
\begin{document}
This is Some Visible Text
\placetextbox{0.5}{0.5}{\phantom{INVISIBLE TEXT HERE}}
\end{document}

You simply replace INVISIBLE TEXT HERE with the command you want executed, but do not want the output text from.

The solution above is based on Werner's answer to a different question. However, in that case, they were not trying to make the text invisible, or execute a command while discarding the resultant text.

For example, if you are using bibtex and you want something in your bibliography without having any in-text citations, then INVISIBLE TEXT HERE might be something like:

\cite{Miller78} \cite{Bubba94}
IdleCustard
  • 1,194
  • 1
    \placetextbox looks like it is based on https://tex.stackexchange.com/q/24663/35864. If that is the case the courteous thing to do is to acknowledge the earlier work that you build on. – moewe Jan 11 '19 at 04:09
  • 4
    The standard way to get references in the bibliography without citing them explicitly in the text is \nocite. \nocite{sigfridsson,worman} will add the two entries sigfridsson and worman to the bibliography even if they have not been cited. \nocite{*} adds all available entries to the bibliography. (See https://tex.stackexchange.com/q/17128/35864) – moewe Jan 11 '19 at 04:10
  • @moewe Yes, \nocite is a lot better than what I did. Thank you. – IdleCustard Jan 12 '19 at 00:01
  • the question as asked would have been answered by simply \sbox0=\hbox{...} as that executes the commands in ... but (if you don't use the box) hides them. It would not answer your cite use case but that was not in the question. (and this is completely the wrong approach for that use case as moewe has pointed out) Also as you have used \phantom this answer would work for \cite but not for example anything using \label. – David Carlisle Jan 13 '19 at 12:26