[Tex/LaTex] Legendre symbol in theory of numbers

fractionsmath-modesymbols

How can I get a Legendre symbol

example,

which just used the dashed line instead of the fractional rule?

Best Answer

\documentclass[a4paper]{article}
\usepackage{amsmath}
\makeatletter
\def\legendre@dash#1#2{\hb@xt@#1{%
  \kern-#2\p@
  \cleaders\hbox{\kern.5\p@
    \vrule\@height.2\p@\@depth.2\p@\@width\p@
    \kern.5\p@}\hfil
  \kern-#2\p@
  }}
\def\@legendre#1#2#3#4#5{\mathopen{}\left(
  \sbox\z@{$\genfrac{}{}{0pt}{#1}{#3#4}{#3#5}$}%
  \dimen@=\wd\z@
  \kern-\p@\vcenter{\box0}\kern-\dimen@\vcenter{\legendre@dash\dimen@{#2}}\kern-\p@
  \right)\mathclose{}}
\newcommand\legendre[2]{\mathchoice
  {\@legendre{0}{1}{}{#1}{#2}}
  {\@legendre{1}{.5}{\vphantom{1}}{#1}{#2}}
  {\@legendre{2}{0}{\vphantom{1}}{#1}{#2}}
  {\@legendre{3}{0}{\vphantom{1}}{#1}{#2}}
}
\def\dlegendre{\@legendre{0}{1}{}}
\def\tlegendre{\@legendre{1}{0.5}{\vphantom{1}}}
\makeatother

\begin{document}
$\genfrac(){}{0}{a}{b}$

$\dlegendre{a}{b}\dlegendre{10}{20}$

$\genfrac(){}{}{a}{b}\legendre{a}{b}\legendre{100}{200}$

$\scriptstyle\genfrac(){}{}{a}{b}\legendre{a}{b}\legendre{10}{20}$

$\scriptscriptstyle\genfrac(){}{}{a}{b}\legendre{a}{b}\legendre{10}{20}$

$\displaystyle\legendre{a}{b}\textstyle\legendre{a}{b}
  \scriptstyle\legendre{a}{b}\scriptscriptstyle\legendre{a}{b}$
\end{document}

The user command are \legendre that typesets the symbol in the current math style or \dlegendre and \tlegendre to force display or text style.

enter image description here

The \genfrac parts are only for comparisons.