2

Related to the question (and accepted answer) at I want a really small underbrace, in which the following code is used to define a new \smallunderbrace command:

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\smallunderbrace#1{\mathop{\vtop{\m@th\ialign{##\crcr
   $\hfil\displaystyle{#1}\hfil$\crcr
   \noalign{\kern3\p@\nointerlineskip}% 
   \tiny\upbracefill\crcr\noalign{\kern3\p@}}}}\limits}
\makeatother
\newcommand{\clap}[1]{\makebox[0pt]{#1}}

\begin{document}
\begin{gather}
  (du) \\
  (\smallunderbrace{du}_{\text{\clap{label}}}) \\
  (\smallunderbrace{\text{test}}_{\text{\clap{label}}})
\end{gather}
\end{document}

The answer (by Paul Gessler) states that the \smallunderbrace command is identical to \underbrace from base LaTeX with the exception of \tiny inserted in the last line.

Can anyone please explain how I can adapt this to define a really small overbrace?

1
  • 1
    copy the overbrace definition from latex.ltx and add \tiny ? Mar 11, 2018 at 21:56

1 Answer 1

10

By similarly adding a \tiny to the definition of \overbrace =).

\documentclass{article}

\usepackage{amsmath}

\makeatletter
\def\smalloverbrace#1{\mathop{\vbox{\m@th\ialign{##\crcr\noalign{\kern3\p@}%
  \tiny\downbracefill\crcr\noalign{\kern3\p@\nointerlineskip}%
  $\hfil\displaystyle{#1}\hfil$\crcr}}}\limits}
\makeatother

\newcommand{\clap}[1]{\makebox[0pt]{#1}}

\begin{document}

\begin{gather}
  (du) \\
  (\smalloverbrace{du}^{\text{\clap{label}}}) \\
  (\smalloverbrace{\text{test}}^{\text{\clap{label}}})
\end{gather}

\end{document}

enter image description here


P.S. There are (at least) five ways to find out how a macro is defined. (Something about teaching a man how to fish.)

1. By using (la)texdef

I don't know if you are a terminal user, but if you are this is a great option. (I think it also works in the command prompt on Windows. Can someone confirm this?)

In a terminal window, type latexdef <macro name> (without a slash), so in this case that'd be latexdef overbrace in this case. This will show you how the macro is defined. If you want to know the definition when certain packages or classes are loaded, you can tell latexdef using -p [<options]<package> flag and -c [<options>]<class> respectively.

Here's an example:

latexdef -c book -p amsmath -p [draft]hyperref chapter

(amsmath, and hyperref don't actually change the definition of \chapter, but I couldn't think of a good example on the fly.)

For more info on latexdef, type latexdef -h, or see the documentation here. You may need to use texdef -t latex instead of latexdef.

2. By using \show

Somewhere in your document, add the following code:

\show\overbrace

When you now run LaTeX it will stop to show you the definition of \overbrace. You can also check the output or the .log file if you are running in nonstopmode.

3. By using \meaning

Somewhere in your document, add the following:

\texttt{\meaning\overbrace}

This will put the definition of \overbrace right in your document. It will look awful without the \texttt because backslashes aren't typeset correctly (unless you use fontenc).

4. By looking at the documentation

You can look at the documentation if you know the package or class in which a macro is defined. To quickly see the documentation for something TeX-related, you can use texdoc: either type texdoc <query> in a terminal or use texdoc.net. Examples: texdoc texdef (texdoc latexdef doesn't work), texdoc hyperref, texdoc symbols-a4 or texdoc texdoc).

The documentation often (but not always) includes the source code. To figure out where a macro is defined you can add the -f flag to latexdef (from method 1). For the documentation on the LaTeX source code, search for source2e.

5. By looking up the .sty/.cls file for the relevant package/class

You can look directly at the source if you know the package or class in which a macro is defined. This can be faster if many definitions are nested and may also be useful because the original code for long definitions is often spread out over multiple lines and indented (and on occasion includes comments).

To figure out where a macro is defined you can add the -f flag to latexdef (from method 1). If latexdef says that a macro is defined by LaTeX then it can probably be found in latex.ltx, in fontmath.ltx, or in one of the other files in the same directory. Where all of these files are located may depend on your TeX distribution and/or OS. To find out where a particular file is, you can type kpsewhich <filename.sty/cls> or kpsewhich <latex.ltx/fontmath.ltx> (again, in a terminal). (And I again think that should also work in Windows, but I'm not sure.)

4
  • Thank you! More fundamentally, then, how do I find out the definition of a given command? (I did try to answer this question beforehand - promise!)
    – user93030
    Mar 11, 2018 at 22:11
  • Good point, that'd probably be more useful to know than just how handle this particular case. Mar 11, 2018 at 22:29
  • May have gotten a little carried away >_> Mar 12, 2018 at 8:08
  • This is just brilliantly helpful - thank you so much! :)
    – user93030
    Mar 12, 2018 at 11:19

You must log in to answer this question.