0

In the first version of the answer to my question Gödel codes with rounded Cornes?, Sandy G offered the following solution:

\newcommand{\godel}[1]{{}\mathbin{\vcenter{\hbox{\tikz{
                    \node[inner ysep=-1pt, inner xsep=3pt](M){$#1\strut$};
                    \draw[rounded corners=.5mm]([xshift=-1mm]M.north east)--(M.north east)--++(0,-.1);
                    \draw[rounded corners=.5mm]([xshift=1mm]M.north west)--(M.north west)--++(0,-.1);
    }}}}{}}

The solution is quite satisfactory for my document, except that many errors are produced, so that the document does not compile, if I put $\godel{A}$ in the title of a section. I tried two ways to protect it, via. $\protect\godel{A}\protect$ and $\protect\godel[thick]{A}$.

Are there other ways to protect $\godel{A}$ in section titles which may help me out?

16
  • 2
    \DeclareRobustCommand instead of \newcommand
    – egreg
    Commented Feb 9, 2023 at 21:30
  • Please edit your query to reproduce some of the error messages you say you're getting. The reason I ask for this is that executing either \subsection{.$\godel{a}$.} or \subsection{.$\godel[thick]{a}$.}(with the macro \godel having been copied from the answer you reference) produces no errors on my system -- MacOS 13.2 "Ventura"; MacTeX2022; pdfTeX Version 3.141592653-2.6-1.40.24; LaTeX2e <2022-11-01> patch level 1; and L3 programming layer <2023-02-07>. Note that I don't find there's a need for \protect.
    – Mico
    Commented Feb 9, 2023 at 21:33
  • 3
    Incidentally, what makes you think that "Sandy G" is a male?
    – Mico
    Commented Feb 9, 2023 at 21:36
  • @egreg Unfortunately that did not succeed. Commented Feb 9, 2023 at 21:51
  • @Sapiens - Please tell us more about your TeX distribution and when you last updated it.
    – Mico
    Commented Feb 9, 2023 at 22:02

1 Answer 1

1

This works flawlessly:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\godel}{}% just to avoid redefining
\DeclareRobustCommand{\godel}[1]{%
  \mspace{1\medmuskip}%
  \vcenter{\hbox{%
    \begin{tikzpicture}
      \node[inner ysep=-1pt, inner xsep=3pt](M){$#1\strut$};
      \draw[rounded corners=.5mm]([xshift=-1mm]M.north east)--(M.north east)--++(0,-.1);
      \draw[rounded corners=.5mm]([xshift=1mm]M.north west)--(M.north west)--++(0,-.1);
    \end{tikzpicture}%
  }}%
  \mspace{1\medmuskip}%
}

\begin{document}

\tableofcontents

\section{$x\godel{A}y$}

\end{document}

Note that I've changed how to space the construction: using {}\mathbin{...}{} introduces flexible space, that's obviously not wanted: if the formula turns out to need shrinking the space might disappear. Not with \mspace{1\medmuskip}, which is not flexible (and the same amount added by default around a \mathbin).

enter image description here

A better definition:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\DeclareRobustCommand{\godel}[1]{%
  \mspace{1\medmuskip}%
  \vphantom{#1}%
  \begin{tikzpicture}[baseline=(M.south)]
    \node[inner ysep=0pt,inner xsep=3pt](M){\smash[b]{$#1\mathstrut$}};
    \draw[rounded corners=.5mm]([xshift=-1mm]M.north east)--(M.north east)--++(0,-.1);
    \draw[rounded corners=.5mm]([xshift=1mm]M.north west)--(M.north west)--++(0,-.1);
  \end{tikzpicture}%
  \mspace{1\medmuskip}%
}

\begin{document}

\tableofcontents

\section{$x\godel{A}y$}

a $\godel{f}$ b

\end{document}

enter image description here

2
  • Many thanks! Unfortunately it does not compile my 50 page document, whereas the solution provided by Sandy G now works, after five hours of editing. The main error I had done was to write, e.g. $\godel{r\in r}$, and not $\godel{$r\in r$}$. I will be interested in using your approach in new documents, from the beginning. Commented Feb 10, 2023 at 3:10
  • 1
    See tex.stackexchange.com/a/674742/4427 for a more refined version of the code
    – egreg
    Commented Feb 10, 2023 at 18:19

You must log in to answer this question.

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