9

I would like to overload some symbols. Basically they would take no space so

\symbol1\symbol2\symbol3

would exist on the page in the same position as either one of the symbols.

Ideally I'd like position/offset to them relative to the first but I don't wanna go through a bunch of trouble to do so. (not setup a tikz environment just to draw a few unique symbols)

Note that I want the symbols to overlap.

e.g.,

\ and / would create an x like symbol, etc.

Because the symbols might not align perfectly the way I would like, I will probably need to position them slightly.

1
  • @campa I don't care about syntax, any syntax, as long as it is short and terse! e.g., \s1\ol{-1em}{-2.5cm}{\s2} So that symbol s2 is offset -1,-2.5 from symbol s1. (ideally, device independent scale would be used) Feb 2, 2018 at 10:25

2 Answers 2

14

EDITED to condense the syntax.

Here I provide \mo[<alignment>]{<symbol list>}. I have set it up to use a space as a symbol list separator (though note that a macro as a symbol will require a trailing {} in order for the subsequent space to be recognized). Alignment can be l, c, or r (default c).

The macros X{<horizontal shift in ex>} and \Y{<vertical shift in ex>}{} are also provided.

BY POPULAR DEMAND, additional macros are provided: \FH[<scale>]{<symbol>} for horizontal flipping, \FV[<scale>]{<symbol>} for vertical flipping in the same footprint as the original glyph, \R{<angle>}{<symbol>} for rotating the symbol about its center, and \SC{<scale>}{<symbol>} for scaling a symbol. The 2nd and 4th lines of the output demonstrate these new capabilities.

\documentclass{article}
\usepackage{stackengine,graphicx}
\newcommand\X[1]{\kern#1ex}
\newcommand\Y[2]{\raisebox{#1ex}{#2}}
\newcommand\FH[2][1]{\scalebox{-#1}[#1]{#2}}
\newcommand\FV[2][1]{\R{180}{\FH[#1]{#2}}}
\newcommand\R[2]{\rotatebox[origin=c]{#1}{#2}}
\newcommand\SC[2]{\scalebox{#1}{#2}}
\newcommand\mo[2][c]{%
  \bgroup%
  \setstackEOL{ }% 
  \setstackgap{L}{0pt}%
  \Longstack[#1]{#2}%
  \egroup%
}
\begin{document}
\newcommand\sd{\makebox[1pt]{.}}
\def\tmp{
\mo{/ \textbackslash}
\mo{O \sffamily I \Y{.23}{$-$}}
\mo[l]{$|$ \X{.21}=}
\mo{$-$ )\X{.1} \X{.1}(}
\mo{. \Y{.1}{\sd\X{.2}\sd} \Y{.4}{\sd\X{.4}\sd} \Y{.9}{\sd\X{.6}\sd} \Y{1.6}{\sd\X{.8}\sd}}

\mo{\FH{b} b}
\mo{\FH[.7]{b} \SC{.7}{b}}
\mo{\R{45}{b} \R{-45}{\FH{b}}}
\mo{Q \FV{Q}}
\mo{\R{90}{j} \FV{j}}}
\tmp\par\LARGE\tmp
\end{document}

enter image description here

5
  • One extra request. Is there any easy way to integrate flipping and rotating? ;) (similar to positioning, such as \R{30} for a 30 degree rotation and maybe \FH for a horizontal flip) and, hell, while we are at it, scaling ;) While we are at it, maybe arbitrary transforms?? just joking! ;) Feb 2, 2018 at 15:16
  • @AbstractDissonance Done. Feb 2, 2018 at 16:16
  • The only problem with this now seems to be that stuff that occurs afterwards is also shifted so it ends up overlapping the symbol. This happens in math mode, e.g. \mo{O\X{-2}Y} QQ. QQ will end up not starting after the symbol because it too gets shifted -2 units(seems to start after the last symbol, Y in this case, rather than the total size. I am using this in a macro and such so it might be a subtle issue.I wrapped an extra {} around the inner macro definition and it seemed to fix it, but not sure if it is the best way as the text that follows seems to be a bit tight(should have more space). Feb 3, 2018 at 16:20
  • in fact, I'd like it probably to either be the max of the total system(all elements) or just the first(since the first generally is the main symbol). Feb 3, 2018 at 16:24
  • @AbstractDissonance Your example isn't actually overlaying any symbols, because there is no space in the argument. Also, in general, negative X shifts can screw up alignment to surrounding material, as you observed. Try this: $\mo{Y \X{.5}O} QQ$ Feb 3, 2018 at 16:31
4

You can use \ooalign; the only problem is finding a suitable syntax: here's an attempt.

  • The *-variant uses text mode
  • The optional argument should be a math type selector (by default the type is ordinary)
  • Items to be overlaid are separated by commas, with a possible [<length>] prefix to denote a shift.

Note that shifting may push the symbol outside the overall bounding box.

The overlay scales in sub/superscripts.

\documentclass{article}
\usepackage{amsmath,xparse}

\ExplSyntaxOn
\cs_new_protected:Nn \dissonance_ooalign:n
 {
  \text{\ooalign{#1\crcr}}
 }
\cs_generate_variant:Nn \dissonance_ooalign:n { V }

\NewDocumentCommand{\overlaysymbols}{sO{}m}
 {
  \IfBooleanTF{#1}
   {
    \cs_set_eq:NN \__dissonance_maybemath:n \use:n
   }
   {
    \cs_set_eq:NN \__dissonance_maybemath:n \ensuremath
   }
  \seq_set_split:Nnn \l_dissonance_ooalign_in_seq { , } { #3 }
  \tl_clear:N \l_dissonance_ooalign_out_tl
  \tl_gclear:N \g__dissonance_ooalign_phantom_tl
  \seq_map_inline:Nn \l_dissonance_ooalign_in_seq
   {
    \tl_put_right:Nn \l_dissonance_ooalign_out_tl
     {
      \__dissonance_ooalign_item ##1 \q_stop
     }
   }
  #2 { \dissonance_ooalign:V \l_dissonance_ooalign_out_tl }
  \vphantom{ \tl_use:N \g__dissonance_ooalign_phantom_tl }
 }

% slight abuse for using optional arguments
\NewDocumentCommand{\__dissonance_ooalign_item}{ou{\q_stop}}
 {
  \tl_gput_right:Nn \g__dissonance_ooalign_phantom_tl
   {
    \__dissonance_maybemath:n { #2 }
   }
  \hfil
  \IfValueT{#1}{\hspace{#1}}
  \__dissonance_maybemath:n { #2 }
  \IfValueT{#1}{\hspace{-#1}}
  \hfil
  \cr
 }

\seq_new:N \l_dissonance_ooalign_in_seq
\tl_new:N \l_dissonance_ooalign_out_tl

\ExplSyntaxOff

\begin{document}

\setlength{\fboxsep}{-0.1pt}
\setlength{\fboxrule}{0.1pt}

$a\overlaysymbols[\mathbin]{/,\backslash}b_{\overlaysymbols{p,q}}$\quad
\fbox{$\overlaysymbols{/,\backslash}$}

\fbox{$\overlaysymbols{+,\times}$}

\fbox{$\overlaysymbols{+,[.1em]\times}$}

\overlaysymbols*{O,\sffamily I, \raisebox{.23ex}{$-$}}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .