[Tex/LaTex] Invisible and unselectable text

boxesheightspacingtransparencyvertical alignment

For alignment reasons (for boxes that align themselves on the text they contain), I currently use this command :

\newcommand{\uplowtext}[1]{
    \transparent{0.}TJPtjp
    \transparent{1.}#1
    \transparent{0.}TJPtjp
}

to make all boxes with the same height by adding an invisible "TJPtjp" before and after the text. But the problem is when someone copy/paste the text from the pdf: he can see the "TJPtjp".

Instead of text, how to put one invisible "box" of the height of "TJPtjp" before and after the text, aligned as a text, so that it will act as a vertical spacer.

Best Answer

LaTeX has an undocumented but very useful feature:

\phantom{text}
\hphantom{text}
\vphantom{text}

will create “phantoms”; they occupy the same space of text, but \hphantom just for the width (no height and depth) and \vphantom just for the height and depth (no width). In any case no character will appear, just the space they would occupy.

For TeXnical reasons, you should add \leavevmode before any of these commands (unless you are sure they will be used in LR-mode or math mode).

So what you want seems to be

\newcommand{\fake}[1]{\leavevmode\hphantom{#1}}

and \fake{0.} instead of \transparent{0.). Your code would become

\newcommand{\fake}[1]{\leavevmode\hphantom{#1}}
\newcommand{\uplowtext}[1]{%
  \fake{0.}TJPtjp
  \fake{1.}#1
  \fake{0.}TJPtjp
}