New symbol derived from [a, b]

Before someone comes with a TikZ solution...

\documentclass{article}

% \usepackage{amsmath}

\makeatletter
\newcommand*{\foo}{\mathpalette\@foo}
\newcommand*{\@foo}[2]{%
   % rule thickness
   \@tempdima=\fontdimen8
       \ifx#1\displaystyle\textfont\else
       \ifx#1\textstyle\textfont\else
       \ifx#1\scriptstyle\scriptfont\else
       \scriptscriptfont\fi\fi\fi 3
   % spacing around the symbols 0.5ex
   \@tempdimb=0.5\fontdimen5
       \ifx#1\displaystyle\textfont\else
       \ifx#1\textstyle\textfont\else
       \ifx#1\scriptstyle\scriptfont\else
       \scriptscriptfont\fi\fi\fi 2
   \sbox0{\m@th\kern\@tempdimb$#1#2$\kern\@tempdimb}%
   \ht0=\dimexpr\ht0+\@tempdimb\relax
   \dp0=\dimexpr\dp0+\@tempdimb\relax
   \lower\dimexpr\dp0+\@tempdima\relax
      \hbox{%
        \vrule\@width\@tempdima
        \vbox{\offinterlineskip
          \hb@xt@\wd0{\vrule\@height\@tempdima\@width\@tempdimb\hfil\vrule\@height\@tempdima\@width\@tempdimb}%
          \box0
          \hrule\@height\@tempdima
        }%
        \vrule\@width\@tempdima
      }%
}
\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}

The two lengths scale accordingly to the current math style: \@tempdima is the standard rule thickness, while \@tempdimb is basicall half ex (the latter could be fixed without resorting to \fontdimen).

enter image description here

If you uncomment amsmath then the result will differ slightly in \scriptscriptstyle, where you get

without amsmath: enter image description here

with amsmath: enter image description here


If your symbols don't have excessive depth (no fractions, for instance), you can get away with

\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}

enter image description here

Tags:

Draw