I want to test if two somewhat arbitrary things typeset as exactly the same thing. For example I would like the test to tell me that abc is different from xyz, but is the same as \def\bar{abc}\bar. A poorly designed test and MWE is




\iftypesetsame{xyz}{zyx}{same}{different} % Test gets it wrong

\iftypesetsame{a\vspace{1in}\par b}{ab}{same}{different} % Test gets it wrong

which tests based on the height, width and depth of the box. This is obviously not very robust because two very different things (e.g., xyz and zyx) can have the same width, height, and depth. It also doesn't handle arbitrary inputs (e.g., \par and \vspace}.

While I would like a perfect LaTeX solution, I would be interested in tests that fail less frequently of even LuaTeX based solutions

  • 5
    The input processor doesn't have access to the typesetting engine: when a box has been packed you can look at its dimensions, but not at what is inside it. For instance, if you do \setbox0=\hbox{a} you can't check whether the box contains an a. You probably need LuaTeX, which has access to the nodes in a typeset box. – egreg Nov 21 '13 at 10:49
  • @egreg so maybe the test cannot be perfect, but there must be tests that don't fail as often as my test. – StrongBad Nov 21 '13 at 11:04

There's no way, in standard TeX, to see inside an already packaged box; one can unbox it, but one can only remove the last item if it's a penalty or a skip (the process can be repeated, but it stops at any other item).

The list inside a typeset box is unreachable from the user's level and it's stored down in the bowels of TeX. Basically you can only test for the dimensions of the box, which of course isn't a reliable test.

With LuaTeX one has access to almost every level, via suitable callbacks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.