0

I would like to redefine the product commands (\times, \cdot, \otimes, \wedge, \odot) to add an optional negative spacing argument, but I don't know how to do this in a proper way. I need the new \times command to stays the same as the old \times when no argument is added to it, and \times[?] (or \times{?} ??) be the command with a negative space added to the left side. How to do that in a proper way?

More specifically, I need the new command to work in the following way:

a \times b gives the same output as the old a \times b.

a \time[1] b gives the same output as a \mskip-1mu \times b

a \time[2] b gives the same output as a \mskip-2mu \times b

Here's a MWE code to play with:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tensor}

\begin{document}

TEST
\begin{align}
    a &\times b \\
    a \mskip-1mu &\times b \\
    a \mskip-2mu &\times b
\end{align}

\end{document}
4
  • 2
    why not simply \def\z#1{\muskip-#1mu} then a \z1\times b does what you want with only three characters, the same as the suggested [1] without redefining standard commands and making your math fragments incompatible with every other latex math setup – David Carlisle Jan 30 at 20:26
  • @DavidCarlisle, just for uniformization of my preamble, what would be your command syntax using the \newcommand* style? – Cham Jan 30 at 20:44
  • 1
    \newcommand\z[1]{\muskip-#1mu} – David Carlisle Jan 30 at 20:46
  • @DavidCarlisle, thanks a lot. I think I'll use your command... – Cham Jan 30 at 20:47
2

You would need to redefine a lot of standard commands which would make your math expressions very fragile and likely to clash with other packages and confuse co-authors.

I would simply define something like

\newcommand\z[1]{\mskip-#1mu}

then use

a \z1\times b

when you want to adjust the spacing. (You might want to give a more meaningful name than \z or perhaps not, and keep it short)

7
  • Would simply \1 be allowed? – Cham Jan 30 at 21:16
  • No, I mean something like \1, \2, ... – Cham Jan 31 at 0:02
  • @Cham well I showed you how to define \1 you can define \2 the same way. You could define \3 as well. (although that is usually the same as \! I doubt you would need anything bigger for small adjustments – David Carlisle Jan 31 at 0:06
  • Ok thanks. I'll experiment with all this... – Cham Jan 31 at 0:07
  • Your macro doesn't work. I'm getting an error message: Bad register code (-1). Missing number, treated as zero. – Cham Jan 31 at 18:23
0

You can abstract the redefinitions:

\documentclass{article}
\usepackage{amsmath}

\ExplSyntaxOn
\NewDocumentCommand{\addspacer}{m}
 {
  \clist_map_function:nN { #1 } \cham_addspacer:N
 }

\cs_new_protected:Nn \cham_addspacer:N
 {
  \exp_args:Nc \NewCommandCopy { \cs_to_str:N #1 _kept } #1
  \RenewDocumentCommand #1 { O{0} }
   {
    \mskip-##1mu
    \use:c { \cs_to_str:N #1 _kept }
   }
 }

\ExplSyntaxOff

\addspacer{\times,\cdot,\otimes,\wedge}

\begin{document}

$a\times b$

$a\times[1]b$

$a\times[2]b$

$a\wedge b$

$a\wedge[1]b$

$a\wedge[2]b$

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.