2

I'm using phantom to maintain even spacing between the teacher version and the student version of a document. I have a newcommand that puts text from the teacher version into a phantom in the student version. However, phantom doesn't seem to like the double dollar sign mathmode.

Is there a workaround?

MWE:

\documentclass{article}
\usepackage{amsmath}


\begin{document}
I want this phantom to work:

\phantom{$$\mathit{\dfrac{14}{20} = 0.7 = 70\%}$$ } 

It works when there's no phantom

$$\mathit{\dfrac{14}{20} = 0.7 = 70\%}$$


It works with a single \$ around the math:

\phantom{$\mathit{\dfrac{14}{20} = 0.7 = 70\%}$ } 

bla bla bla

\end{document}
5
  • What's the purpose of the \mathit wrappers?
    – Mico
    Jul 14, 2023 at 1:18
  • With the amount of space you're leaving between equations, I assume the use of a math display is not really of concern here? That is, you might as well set the content in an inline math construction with \displaymath, since typically one shouldn't leave a blank line before a math display.
    – Werner
    Jul 14, 2023 at 1:22
  • \phantom uses a savebox to compute the size needed. In particular, it uses an \hbox type savebox, and you need a \vbox type savebox to handle $$ (or \{ or \begin{equation) etc.) Jul 14, 2023 at 15:43
  • I'm italicizing all of the content from the teacher version to make it more obvious which text is from the key and which is in the original document. In the teacher version, I like the spacing that $$ gives. I'm fine with using [ ] instead, but that doesn't seem to be fixing the problem.
    – user26305
    Jul 14, 2023 at 19:35
  • I have used boxes but I'm definitely not fluent with them. Would it be possible to do some sort of \renewcommand and replace \phantom's \hbox with a \vbox? Or would that create a new set of problems?
    – user26305
    Jul 14, 2023 at 21:28

2 Answers 2

1

The first thing to say is: never use $$ in a LaTeX document environment.

What happens in your case can be explained: \phantom creates a horizontal box with the same dimensions as the material inside it. In such a horizontal box, it's not possible to make paragraphs, so display math mode is disallowed and $ just starts math mode. A following $ simply ends math mode. So you get an empty formula followed by \mathit in text mode, which triggers the error.

If you want to make a double version, it's better to define structures. This is a basic framework just to give you an idea.

\documentclass[twocolumn]{article}
\usepackage{amsmath}

\newif\ifstudent
\newcommand{\equ}[1]{%
  \[
  \ifstudent\else\expandafter\phantom\fi{#1}
  \]%
}


\begin{document}

\section{With phantom}

I want this phantom to work:
\equ{\dfrac{14}{20} = 0.7 = 70\%}
It works when there's no phantom
\[
\dfrac{14}{20} = 0.7 = 70\%
\]
Some text follows.

\newpage

\section{Clear text}
\studenttrue

I want this phantom to work:
\equ{\dfrac{14}{20} = 0.7 = 70\%}
It works when there's no phantom
\[
\dfrac{14}{20} = 0.7 = 70\%
\]
Some text follows.

\end{document}

enter image description here

0

There are two ways to interpret your posting. Removing the redundant \mathit wrappers and using \[ ... \] instead of $$ ... $$ -- see also Why is [ ... ] preferable to $$ ... $$? --, you could be looking for either

\[ \phantom{\frac{14}{20} = 0.7 = 70\%} \]

or

$ \phantom{\dfrac{14}{20} = 0.7 = 70\%}$

The first option places the phantom inside an unnumbered displayed equation environment. The second places the phantom in running text.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .