Skip to main content
Commonmark migration
Source Link
  1. The bounding box of % is not a square. Additional margins can be added to increase the frame to a square. Or the symbol can be resized. In this case the symbol is not far from a square, thus a little distorting does hurt less than different inner margins.

  2. A scale factor for the rule width adaptation is calculated by comparing the height of the symbol in normal size with the height of the symbol in the current size.

  3. Rounded corners can easily be made with tikz' line join=round.

  4. Shrinking and moving a box can be easily done with \resizebox, \scalebox and \raisebox. The dimensions of the box are available inside the arguments of these commands through \width, \height, ...

  5. Getting rid of the side bearings is the tough part, because TeX does not know the size of the side bearings. It uses only the official glyph bounding box that includes the side bearings.

    LuaTeX could be tried to look into the internal font data. With some luck, the size of the side bearings can be obtained.

LuaTeX could be tried to look into the internal font data. With some luck, the size of the side bearings can be obtained.

  1. The bounding box of % is not a square. Additional margins can be added to increase the frame to a square. Or the symbol can be resized. In this case the symbol is not far from a square, thus a little distorting does hurt less than different inner margins.

  2. A scale factor for the rule width adaptation is calculated by comparing the height of the symbol in normal size with the height of the symbol in the current size.

  3. Rounded corners can easily be made with tikz' line join=round.

  4. Shrinking and moving a box can be easily done with \resizebox, \scalebox and \raisebox. The dimensions of the box are available inside the arguments of these commands through \width, \height, ...

  5. Getting rid of the side bearings is the tough part, because TeX does not know the size of the side bearings. It uses only the official glyph bounding box that includes the side bearings.

LuaTeX could be tried to look into the internal font data. With some luck, the size of the side bearings can be obtained.

  1. The bounding box of % is not a square. Additional margins can be added to increase the frame to a square. Or the symbol can be resized. In this case the symbol is not far from a square, thus a little distorting does hurt less than different inner margins.

  2. A scale factor for the rule width adaptation is calculated by comparing the height of the symbol in normal size with the height of the symbol in the current size.

  3. Rounded corners can easily be made with tikz' line join=round.

  4. Shrinking and moving a box can be easily done with \resizebox, \scalebox and \raisebox. The dimensions of the box are available inside the arguments of these commands through \width, \height, ...

  5. Getting rid of the side bearings is the tough part, because TeX does not know the size of the side bearings. It uses only the official glyph bounding box that includes the side bearings.

    LuaTeX could be tried to look into the internal font data. With some luck, the size of the side bearings can be obtained.

replaced http://tex.stackexchange.com/ with https://tex.stackexchange.com/
Source Link

This answer is a continuation of tohecz' answeranswer.

This answer is a continuation of tohecz' answer.

This answer is a continuation of tohecz' answer.

Bounty Awarded with 100 reputation awarded by yo'
Example changed.
Source Link
Heiko Oberdiek
  • 277.9k
  • 25
  • 741
  • 1.1k

This answer is a continuation of the tohecz' answer.

ResultResult

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\makeatletter
\newcommand*{\squareboxed@}[5]{%
  \sbox0{$#1#2\m@th$}%
  % remove side bearings
  \sbox0{%
    \kern-#4\wd0 %
    \unhcopy0 %
    \kern-#5\wd0 %
  }%
  % resize to square
  \dimen@=\dimexpr\ht0+\dp0-\wd0\relax
  \ifdim\dimen@=\z@
  \else
    \sbox0{\resizebox{\totalheight}{\height}{\unhcopy0}}%
  \fi
  % shrink and put on math axis
  \sbox2{$#1\vcenter{}$}%
  \sbox0{%
    \raisebox{\ht2}{%
      \scalebox{#3}{%
        \raisebox{.5\dimexpr\dp0-\ht0\relax}{\unhcopy0}%
      }%
    }%
  }%
  % scale \fboxrule
  \sbox2{$1$}%
  \sbox4{$#11$}%
  \fboxrule=\dimexpr\fboxrule*\ht4/\ht2\relax
  % add inner sep
  \fboxsep=.5\dimexpr#4\wd0+#5\wd0\relax
  \kern\fboxsep
  \sbox2{$#1X$}%
  \resizebox{!}{\ht2}{%
    \raisebox{\depth}{%
      \tikz[
        inner sep=\fboxsep,
        line width=\fboxrule,
        line join=round,
        baseline=(X.base),
      ]
        \node[draw](X){\copy0}%
      ;%
    }%
  }%
  \kern\fboxsep
}
\newcommand*{\squareboxed}[8]{%
  \mathchoice
    {\squareboxed@\displaystyle{#1}{#2}{#3}{#4}}%
    {\squareboxed@\textstyle{#1}{#2}{#3}{#4}}%
    {\squareboxed@\scriptstyle{#1}{#2}{#5}{#6}}%
    {\squareboxed@\scriptscriptstyle{#1}{#2}{#7}{#8}}%
}

\newcommand*{\boxmod}{%
  \mathbin{%
    \squareboxed
      {\%}   {.8}
      {.065} {.07}
      {.07}  {.075}
      {.085} {.09}%
  }%
}
\makeatother

\begin{document} 

  \[\noindent
   $ X \boxmod YY$\\
  $ r \stackrel{%
\boxmod i ^ {r \boxmod i \stackrel{X\boxmod^ Y}{i\boxmod r} 
   \boxmod i}{=}$\\
    i$ \boxmodn r- (n \boxmod m)$
  \]
\end{document}

This answer is a continuation of the tohecz' answer.

Result

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\makeatletter
\newcommand*{\squareboxed@}[5]{%
  \sbox0{$#1#2\m@th$}%
  % remove side bearings
  \sbox0{%
    \kern-#4\wd0 %
    \unhcopy0 %
    \kern-#5\wd0 %
  }%
  % resize to square
  \dimen@=\dimexpr\ht0+\dp0-\wd0\relax
  \ifdim\dimen@=\z@
  \else
    \sbox0{\resizebox{\totalheight}{\height}{\unhcopy0}}%
  \fi
  % shrink and put on math axis
  \sbox2{$#1\vcenter{}$}%
  \sbox0{%
    \raisebox{\ht2}{%
      \scalebox{#3}{%
        \raisebox{.5\dimexpr\dp0-\ht0\relax}{\unhcopy0}%
      }%
    }%
  }%
  % scale \fboxrule
  \sbox2{$1$}%
  \sbox4{$#11$}%
  \fboxrule=\dimexpr\fboxrule*\ht4/\ht2\relax
  % add inner sep
  \fboxsep=.5\dimexpr#4\wd0+#5\wd0\relax
  \kern\fboxsep
  \sbox2{$#1X$}%
  \resizebox{!}{\ht2}{%
    \raisebox{\depth}{%
      \tikz[
        inner sep=\fboxsep,
        line width=\fboxrule,
        line join=round,
        baseline=(X.base),
      ]
        \node[draw](X){\copy0}%
      ;%
    }%
  }%
  \kern\fboxsep
}
\newcommand*{\squareboxed}[8]{%
  \mathchoice
    {\squareboxed@\displaystyle{#1}{#2}{#3}{#4}}%
    {\squareboxed@\textstyle{#1}{#2}{#3}{#4}}%
    {\squareboxed@\scriptstyle{#1}{#2}{#5}{#6}}%
    {\squareboxed@\scriptscriptstyle{#1}{#2}{#7}{#8}}%
}

\newcommand*{\boxmod}{%
  \mathbin{%
    \squareboxed
      {\%}   {.8}
      {.065} {.07}
      {.07}  {.075}
      {.085} {.09}%
  }%
}
\makeatother

\begin{document}
  \[
    X \boxmod Y
    \stackrel{%
      \stackrel{X\boxmod Y}{i\boxmod r} 
    }{=}
    i \boxmod r   
  \]
\end{document}

This answer is a continuation of tohecz' answer.

Result

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}

\makeatletter
\newcommand*{\squareboxed@}[5]{%
  \sbox0{$#1#2\m@th$}%
  % remove side bearings
  \sbox0{%
    \kern-#4\wd0 %
    \unhcopy0 %
    \kern-#5\wd0 %
  }%
  % resize to square
  \dimen@=\dimexpr\ht0+\dp0-\wd0\relax
  \ifdim\dimen@=\z@
  \else
    \sbox0{\resizebox{\totalheight}{\height}{\unhcopy0}}%
  \fi
  % shrink and put on math axis
  \sbox2{$#1\vcenter{}$}%
  \sbox0{%
    \raisebox{\ht2}{%
      \scalebox{#3}{%
        \raisebox{.5\dimexpr\dp0-\ht0\relax}{\unhcopy0}%
      }%
    }%
  }%
  % scale \fboxrule
  \sbox2{$1$}%
  \sbox4{$#11$}%
  \fboxrule=\dimexpr\fboxrule*\ht4/\ht2\relax
  % add inner sep
  \fboxsep=.5\dimexpr#4\wd0+#5\wd0\relax
  \kern\fboxsep
  \sbox2{$#1X$}%
  \resizebox{!}{\ht2}{%
    \raisebox{\depth}{%
      \tikz[
        inner sep=\fboxsep,
        line width=\fboxrule,
        line join=round,
        baseline=(X.base),
      ]
        \node[draw](X){\copy0}%
      ;%
    }%
  }%
  \kern\fboxsep
}
\newcommand*{\squareboxed}[8]{%
  \mathchoice
    {\squareboxed@\displaystyle{#1}{#2}{#3}{#4}}%
    {\squareboxed@\textstyle{#1}{#2}{#3}{#4}}%
    {\squareboxed@\scriptstyle{#1}{#2}{#5}{#6}}%
    {\squareboxed@\scriptscriptstyle{#1}{#2}{#7}{#8}}%
}

\newcommand*{\boxmod}{%
  \mathbin{%
    \squareboxed
      {\%}   {.8}
      {.065} {.07}
      {.07}  {.075}
      {.085} {.09}%
  }%
}
\makeatother

\begin{document} 

  \noindent
  $ X \boxmod Y$\\
  $ r \boxmod i ^ {r \boxmod i ^ {r \boxmod i}}$\\
  $ n - (n \boxmod m)$

\end{document}
Resizing to uppercase letter, align to base line, side bearings outside added.
Source Link
Heiko Oberdiek
  • 277.9k
  • 25
  • 741
  • 1.1k
Loading
Instead of padding the symbol is resized to fit the square. Rounded corners added.
Source Link
Heiko Oberdiek
  • 277.9k
  • 25
  • 741
  • 1.1k
Loading
Source Link
Heiko Oberdiek
  • 277.9k
  • 25
  • 741
  • 1.1k
Loading