1

Consider the following MWE:

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{l3draw,xparse}
\ExplSyntaxOn
%---------------------------------------------------------
\box_new:N \default_math_plus
\hbox_set:Nn \default_math_plus {$+$}

\box_new:N \cplus_box

\dim_new:N \l__default_math_plus_width \dim_set:Nn \l__default_math_plus_width { \box_wd:N \default_math_plus}

\fp_new:N \l__expl_cplus_fp

\cs_new_protected:Nn \expl_cplus: { \draw_begin: \draw_linewidth:n { \l__expl_cplus_fp } \draw_cap_round: \draw_join_round: \draw_path_moveto:n { 0.5\l__default_math_plus_width , 0.0\l__default_math_plus_width } \draw_path_lineto:n { 0.5\l__default_math_plus_width , 1.0\l__default_math_plus_width } \draw_path_use_clear:n { stroke } \draw_path_moveto:n { 0.0\l__default_math_plus_width , 0.5\l__default_math_plus_width } \draw_path_lineto:n { 1.0\l__default_math_plus_width , 0.5\l__default_math_plus_width } \draw_path_use_clear:n { stroke } \draw_path_circle:nn { 0.5\l__default_math_plus_width , 0.5\l__default_math_plus_width } {0.25\l__default_math_plus_width} \draw_path_use_clear:n { stroke } \draw_end: } \NewDocumentCommand{\explcplus}{} { \mathbin { \fp_set:Nn \l__expl_cplus_fp { 0.08ex } \hbox_set:Nn \cplus_box { $\mspace{1mu}$ \expl_cplus: $\mspace{1mu}$ } \box_move_down:nn { \box_dp:N \default_math_plus }{ \box_use:N \cplus_box } } }

%--------------------------------------------------------- \ExplSyntaxOff

\begin{document} $a+b\explcplus c_{+\explcplus}$

$a\explcplus b+c_{+\explcplus}$

\medskip

% test for larger size

{\LARGE$a\explcplus b+c_{+\explcplus}$} \end{document}

I am trying to recreate what @egreg did in his answer to: https://tex.stackexchange.com/a/397806/10898 but I cannot seem to get the correct math spaces and depth.

What am I doing wrong? Or how can correctly calculate the + dimensions?

The scaling in the last image is off and seems not to be defined as ex for it to scale appropriately.

azetina
  • 28,884
  • You need to measure the + when the macro is called, otherwise you always get the same size independently on the current font size. – egreg Nov 09 '20 at 17:36
  • @egreg Let me try. :) I am measuring before, right? – azetina Nov 09 '20 at 18:03
  • Indeed you are, when you set \hbox_set:Nn \default_math_plus {$+$}. Once a box has been set, it never changes. By the way, the names are non conformant and “default” is not really a good prefix. – egreg Nov 09 '20 at 18:08
  • @egreg I am still learning the intricacies of this style of coding. Maybe a solution would help me correct my mistakes and suggestions for the conforming style of naming, My apologies. – azetina Nov 09 '20 at 18:16
  • Does the + have different ht and wd? – azetina Nov 09 '20 at 18:23
  • Usually so, because it has some sidebearings that are not reflected in the height and depth, but mainly because it may sit below the baseline, so the horizontal bar is at the formula axis. In Computer Modern it does, in other fonts in may hang a bit above the baseline (new TX, for instance). – egreg Nov 09 '20 at 18:28

0 Answers0