More often than not, when I use the \resizebox{width}{height}{object} command it ends up looking something like this:


I know from places like here that the exclamation mark essentially automatically calculates the appropriate hight so as to retain the same aspect ratio as before.

What I don't know, is this something to do with tex / latex the language in general? Or is it simply syntax specific to the resizebox command? Does the exclamation mark in \begin{figure}[!htbp] have anything to do with that, or is this also simply syntax specific to the internals of the {figure} environment?

In other words, the question is, is the exclamation mark a language construct, and if so what is it, and what might be useful to know about it? And if it's not a language construct and is simply syntax specific to certain functions, is there at least some sort of convention as to its meaning that might be useful to know?

  • 1
    When weird syntax is encountered, remember that TeX programs (I.e., classes, packages, and documents) can modify their own syntax. – Sean Allred Aug 29 '16 at 14:09

This is the definition of \resizebox in graphics.sty (line numbers added for reference):

244 \def\Gin@exclamation{!}

417 \def\resizebox{%
418   \leavevmode
419   \@ifstar{\Gscale@@box\totalheight}{\Gscale@@box\height}}
420 \def\Gscale@@box#1#2#3{%
421   \let\@tempa\Gin@exclamation
422   \expandafter\def\expandafter\@tempb\expandafter{\string#2}%
423   \expandafter\def\expandafter\@tempc\expandafter{\string#3}%
424   \ifx\@tempb\@tempa
425     \ifx\@tempc\@tempa
426       \toks@{\mbox}%
427     \else
428       \toks@{\Gscale@box@dd{#3}#1}%
429     \fi
430   \else
431     \ifx\@tempc\@tempa
432       \toks@{\Gscale@box@dd{#2}\width}%
433     \else
434       \toks@{\Gscale@box@dddd{#2}\width{#3}#1}%
435     \fi
436   \fi
437   \the\toks@}

The *-version uses \totalheight instead of \height and control is passed to \Gscale@@box, which absorbs the two arguments that appear as the arguments to \resizebox. The \string token in lines 422 and 423 is used because babel might have made ! into an active character.

The three conditional compare the arguments to \resizebox with a normal !; if it is found, then the appropriate action is performed.

There's no special meaning for ! in LaTeX or in the general TeX syntax; the developers of LaTeX just chose a character that is not supposed to belong in a dimension setting.

The case of ! in the optional argument to a float environment is similar: just the choice of an easy character, well distinguishable from the other characters with a meaning in that argument.

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.