# Create symbol out of given symbols with same line width

I'm trying to create a new symbol out of a given one $\sqcup$ but it does not work as expected. Have a look at the following minimal example:

\documentclass{article}

\usepackage{graphicx}

\newcommand{\sqqcup}{\,{{\sqcup}\hspace*{-0.6em}\raisebox{-0.25ex}{--}}\;}

\begin{document}
$\scalebox{8}{a \sqqcup b}$
\end{document}


As you can see the extra horizontal line I'm trying to put over the squared cup symbol is not typeset in the same line width/strength.

Has someone an idea how to draw a line with the same line width than an already existing symbol?

-

Basically you have to just do it by eye, as you have done. TeX has no information about the line widths (or the shape of the glyph at all). Even if you look in to the type1 or metafont sources of the font and find out the original design widths, you can not ensure at small sizes that you get exactly the same width using a rule, as the lines in the font are subject to the renderer's font hinting mechanism which may snap the lines on to pixel boundaries, whereas rules are drawn by different mechanisms and not subject to the same hinting.

You might do better just offsetting the same character so the rules are subject to the same hinting:

\documentclass{article}

\usepackage{graphicx}

\newcommand{\sqqcup}{\,{{\sqcup}\hspace*{-0.6em}\raisebox{-0.25ex}{--}}\;}

\def\xsqqcupb#1#2{\mathbin{\rlap{\raisebox{.15em}{$#1#2$}}{#2}}}
\def\sqqcupb{\mathpalette\xsqqcupb\sqcup}

\begin{document}
$\scalebox{8}{a \sqqcup b}$
$\scalebox{8}{a \sqqcupb b}$
\end{document}


Update:

As discussed in the comments it would be possible to hide the extra height with a coloured rule, but beware that the colour may hide more than you intend 9note the top bar of the fbox in the modified example)

\documentclass{article}

\usepackage{graphicx,color}

\newcommand{\sqqcup}{\,{{\sqcup}\hspace*{-0.6em}\raisebox{-0.25ex}{--}}\;}

\def\xsqqcupb#1#2{\rlap{\raisebox{.15em}{$#1#2$}}{#2}}
\def\sqqcupb{\mathbin{\mathpalette\xsqqcupb\sqcup}}

\def\xsqqcupc#1#2{\smash{\rlap{\raisebox{.15em}{$#1#2$}}\rlap{\color{white}\rule[.3em]{0.7em}{1.1ex}}}{#2}}
\def\sqqcupc{\mathbin{\mathpalette\xsqqcupc\sqcup}}

\begin{document}

\fbox{\scalebox{8}{$a \sqqcup x$}}

\bigskip

\fbox{\scalebox{8}{$a \sqqcupb x$}}

\bigskip

\fbox{\scalebox{8}{$a \sqqcupc x$}}

\end{document}

-
Is there a way to hide the upper half of the overlaying symbol to have it of the same height? I can think only of a white rectangle, but that needs colors... – yo' Mar 30 '12 at 9:46
I wondered about that, but it would need colour, and would lose the rounded tips to the uprights. Oh I suppose you could perhaps preserve the tips if you set the raised one, then the white rectangle then the normal one – David Carlisle Mar 30 '12 at 9:52
Setting two times the same symbol is a really nice idea! However, by using a white rectangle, the actual hight of the box would be higher than a box of just $\sqcup$. Are you aware of a command to cut down a symbol? Then I probably could come up with a nice and decent solution. – Stefan Mar 30 '12 at 11:40
\smash is your friend I'll add a version to my answer – David Carlisle Mar 30 '12 at 11:42
Yes I thought about this too but setting a white rectangle has the drawback that if the background is not white too, then it will not look nice (at least not automatically). Hence, I thought about cropping/cutting the second occurance of \sqcup in order to solve this problem. – Stefan Mar 30 '12 at 11:57

As David Carlisle says, there's no completely automatic way to guess the line width. I suggest you to define a generic macro that you can then adjust for the particular font

\newcommand{\gensqqcup}[3]{% #1 = bar height, #2 = bar thickness, #3 = sidebearings
\ooalign{$\sqcup$\cr
\hskip#3em
\leaders\hrule height #1ex depth \dimexpr -#1ex+#2ex\hfill
\hskip#3em\cr}}
\newcommand{\sqqcup}{\mathbin{\gensqqcup{.4}{.1}{.09}}}


The values in the last line seem appropriate for the Computer Modern fonts

The same values can be used with the MathPazo fonts

I've tried also with the KP fonts and the TX fonts, getting in any case a good result.

The three parameters are

• the bar height (in ex units)
• the bar thickness (in ex units)
• the sidebearings of the square cup (to shorten the bar so that it's inside the symbol)

Usually the default for the bar thickness (0.1ex, which for Computer Modern fonts is approximately 0.4pt) can be a good guess. The \ooalign method avoids the need to guess other parameters.

(Thanks to Jake for pointing out that a relative unit of measure is better for the bar thickness.)

If you want the symbol also in subscript and superscripts, a more convolute definition must be used:

\newcommand{\gensqqcup}[4][\textstyle]{% #2 = bar height, #3 = bar thickness, #4 = sidebearings
\ooalign{$#1\sqcup$\cr
\hskip#4em
\leaders\hrule height #2ex depth \dimexpr -#2ex+#3ex\hfill
\hskip#4em\cr}}
\newcommand{\sqqcup}{\mathbin{\mathchoice
{\gensqqcup[\displaystyle]{.4}{.1}{.09}}
{\gensqqcup[\textstyle]{.4}{.1}{.09}}
{\gensqqcup[\scriptstyle]{.3}{.08}{.07}}
{\gensqqcup[\scriptscriptstyle]{.25}{.07}{.07}}
}}


This is what results from

$a \sqqcup b_{\sqqcup_{\sqqcup}}$


With a bit of trial and error you will find the correct parameters for the three sizes.

-
I really like this solution but I have one thing to comment on. If I use the symbol in a subscript it does not scale properly (my original solution does scale neither). For example \scalebox{8}{$f_{A \sqqcup A \sqcup A}$} produces a wrongly sized $\sqqcup$. Probably I demand to much. What would you suggest, is it better to create a complete new symbol if I want it to resize properly in all ways? I'm somehow confused ;) – Stefan Mar 30 '12 at 10:26
@Stefan See edited answer – egreg Mar 30 '12 at 12:15

I borrowed the measures from Jake's answer and tried to improve it in small bits. Firstly, you should surround the code by \mathbin to get proper line-breaking (it is an operator and you should tell that to LaTeX). Then the proper spacing is a bit complicated. I use \mathrlap from mathtools package to type the actual glyph, and \phantom to reserve the space for it.

\documentclass{article}

\usepackage{graphicx}

\usepackage{mathtools}
\newcommand{\sqqcup}{\mathbin{\mathrlap{{\sqcup}\kern-0.6em\rule[0.3ex]{0.52em}{0.1ex}}}\phantom{\sqcup}}

\begin{document}
$\scalebox{8}{a \sqqcup b}$
\end{document}

-

Well, Jake is faster by 90 seconds. But I can not resist the pressure of putting my answer. Pl. be kind not to down vote.

\documentclass{article}
\usepackage{graphicx}
\newcommand{\sqqcup}{\,{{\sqcup}\hspace*{-0.6em}\raisebox{0.25ex}{\vrule width 0.52em height 0.1ex}}\;}
\begin{document}
$\scalebox{8}{a \sqqcup b}$
\end{document}


Thanks to Jakes for recommending em and ex instead of pt.

-