MaTeX and \phantom

7

My understanding of the \phantom directive is that it should preserve the sizes of all elements in the expression. But when I try this:

m1 = Inset[MaTeX["\\sqrt{\\phantom{a^2}b}", Magnification -> 5], {0, 0}];

m2 = Inset[MaTeX["\\sqrt{a^2b}", Magnification -> 5], {0, 0}];

Graphics[{m1, m2}]

I get this:

enter image description here

I would have expected the two square roots to be right on top of each other.

Wynne

Posted 2017-12-03T05:56:34.843

Reputation: 986

Please use code blocks for code, not quote blocks, otherwise some of the code might be destroyed (as it was here). – Szabolcs – 2017-12-03T09:24:11.743

That's a very strange position for one of the b's! – Michael E2 – 2017-12-04T00:27:41.043

Answers

12

The same sizes show up using pure Latex.

\documentclass[11pt]{article}
\begin{document}

\Huge
\[
\sqrt{\phantom{a^2}b}
\]

\[
\sqrt{a^2b}
\]

\end{document}

Gives (compiled with pdflatex)

Mathematica graphics

And this is inside Mathematica:

Mathematica graphics

I do not see any difference. But I think your question is really about Latex itself and not Matex, which just compiles using Latex.

You could see this how-do-i-create-an-invisible-character on Tex Exchange where it says

\phantom inserts an empty box with the same dimensions (horizontal as well as vertical) as the argument

But if you think it is not doing what it should, I would suggest asking at https://tex.stackexchange.com

Update

What you want is \hphantom and not \phantom

m1=Inset[MaTeX["\\sqrt{\\hphantom{a^2}b}",Magnification->5],{0,0}]
m2=Inset[MaTeX["\\sqrt{a^2b}",Magnification->5],{0,0}]

Mathematica graphics

Graphics[{m1,m2}]

Mathematica graphics

Nasser

Posted 2017-12-03T05:56:34.843

Reputation: 92 661

In plain TeX, $\sqrt{\phantom{a^2}b}$ and $\sqrt{{a^2}b}$ seem to coincide. (It could be that LaTeX messes things up. I'm not sure how to use it.) – Michael E2 – 2017-12-04T00:00:43.027

@MichaelE2 that is interesting,. But no one uses Plain TeX anymore, well may be except for Donald Knuth himself :) This could be a good question for tex exchange to explain this difference between TeX and Latex. – Nasser – 2017-12-04T00:04:13.977

And me. :-) Too many packages written in years gone by....When LaTeX came out, it seemed like the kid's version. ;-P -- Wait, do they not coincide in LaTeX? I didn't think LaTeX did anything drastic to TeX, unlike ConTeXt.... – Michael E2 – 2017-12-04T00:07:52.390

@MichaelE2 I just compiled using plain TeX using \phantom and the output is the same as with Latex as shown in the post. i.e. Same spacing difference. They do not coincide. I am using texlive 2017 on Linux. ps. I tried to learn Context, but it is really a completely different system from Latex, so I decided not worth the time. – Nasser – 2017-12-04T00:14:43.527

Isn't that interesting. I'm using pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015), MacOS. I wouldn't think plain TeX would have changed, and from what I know about plain TeX, they should coincide. Ah, well. However, I get the OP's output using MaTeX. – Michael E2 – 2017-12-04T00:19:50.863

@MichaelE2 if you get different result from Tex Vs. Latex using \phantom I think you might want to consider posting this at Tex Exchange as this should not happen and you could have found a bug. It does not happen for me on Latest TeXLive 2017. – Nasser – 2017-12-04T00:25:11.500