I am trying to implement command — let's name it fn
— aimed to behave like overset
command and underline the lower word with some curve. Doing this using TikZ. The lower word is made as node text, and the upper one — as node's label option. And because of that some additional padding is appearing like in MWE below.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xparse}
\newcommand{\tmpText}{}
\NewDocumentCommand{\fn}{ > { \SplitArgument { 1 } { : } } m }{%
{%
\NewDocumentCommand{\tmpSubject}{mm}{%
\IfValueT{##2}{\renewcommand{\tmpText}{##2}}
\tikz[baseline=(Root.base)]{%
\node[inner sep=0pt,
outer sep=0pt,
label={[yshift=-2,
font=\tiny\itshape] \tmpText}] (Root) {##1};
\draw[line width=0.75]
let
\p1 = (Root.south west),
\p2 = (Root.south east)
in
(\x1, \y1 - 2) -- (\x2, \y2 - 2);
}%
}%
\tmpSubject#1%
}%
}
\begin{document}
{\setlength{\fboxsep}{0pt}
\fbox{\fn{Hello:world}}
\fbox{\fn{Hello}}
\fbox{Hello}
}
\end{document}
Which is producing the following output:
So, the main question is whether it is possible to correct paddings so that the output would be as follow (color is only for indicating desired area)? And of course, if the upper text is wider than lower one, width as well should be corrected to the wider text. Alas, could not find the answer myself neither on forum nor in TikZ.
And the additional question is it a good way to define temporary commands inside another command in terms of performance? Like I defined fn
in MWE? My main motivation of such nested macros is not to define function I do not directly need in main document.
Thanks in advance.