
решение1
Прежде чем кто-то придет с ТикZ-решение :-)
...
\documentclass{article}
% \usepackage{amsmath}
\makeatletter
\newcommand*{\foo}[1]{{\mathpalette\foo@{#1}}}
\newcommand*{\foo@}[2]{%
\@tempdima=.5\fontdimen5
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi\tw@
\@tempdimb=\fontdimen8
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi\thr@@
\setbox\z@=\vtop{\hbox{$\m@th#1#2$}\kern\@tempdima}%
\setbox\tw@=\vbox{\hrule\@width\@tempdima\@height\@tempdimb\kern\ht\z@\kern\@tempdima}%
\vtop{\hbox{\vrule\@width\@tempdimb\copy\tw@\copy\z@\copy\tw@\vrule\@width\@tempdimb}\hrule\@height\@tempdimb}%
}
\makeatother
\begin{document}
$\foo{a,b}$
$\scriptstyle\foo{a,b}$
$\scriptscriptstyle\foo{a,b}$
\medskip
$\displaystyle\foo{-\frac{a}{2},\frac{a}{2}}$
$\foo{-\frac{a}{2},\frac{a}{2}}$
$\scriptstyle\foo{-\frac{a}{2},\frac{a}{2}}$
$\scriptscriptstyle\foo{-\frac{a}{2},\frac{a}{2}}$
\end{document}
Две длины масштабируются в соответствии с текущим математическим стилем: \@tempdimb
— толщина правила дроби, а \@tempdima
— половина ex
(последнее можно исправить, не прибегая к \fontdimen
).
Если вы раскомментируете amsmath
, то результат будет немного отличаться в \scriptscriptstyle
, где вы получите
С более коротким кодом
\newcommand*{\foo@}[2]{%
\@tempdima=.5\fontdimen5
\ifx#1\displaystyle\textfont\else
\ifx#1\textstyle\textfont\else
\ifx#1\scriptstyle\scriptfont\else
\scriptscriptfont\fi\fi\fi\tw@
\setbox\z@=\vtop{\hbox{$\m@th#1#2$}\kern\@tempdima}%
\setbox\tw@=\vbox{\hrule\@width\@tempdima\kern\ht\z@\kern\@tempdima}%
\vtop{\hbox{\vrule\copy\tw@\copy\z@\copy\tw@\vrule\@width\@tempdimb}\hrule}%
}
«ящик» имеет толщину по умолчанию 0.4pt
в каждом стиле.
решение2
Если ваши символы не имеют чрезмерной глубины (например, нет дробей), вы можете обойтись без
\documentclass{article}
\usepackage{amsmath,array}
\makeatletter
\newcommand{\segment}[1]{%
\big\lceil\colas@segment{#1}\big\rceil
}
\newcommand{\colas@segment}[1]{%
\mspace{-4.85mu}%
\underline{\mspace{5mu}#1\vphantom{j}\mspace{5mu}}%
\mspace{-4.85mu}%
}
\makeatother
\begin{document}
\Huge
\indent\rlap{\vrule height0pt depth0.1pt width 4cm}%
$\segment{a,b}=\{ta+(1-t)b: t\in[0,1]\}$
\indent\rlap{\vrule height0pt depth0.1pt width 4cm}%
$\segment{p,q}=\{tp+(1-t)q: t\in[0,1]\}$
\end{document}