When writing in mathmode, is it possible to define a * to become \cdot, in the main document?
As it makes it easier when writing equations to make a star.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this community\documentclass{article}
% \DeclareMathSymbol{\cdot}{\mathbin}{symbols}{"01} % from fontmath.ltx
\DeclareMathSymbol{*}{\mathbin}{symbols}{"01}
\begin{document}
$ x * y $
\end{document}
width=0.5\textwidth
Sep 23, 2020 at 11:48
~
is \nobreakspace
but for example if you made *
active to make it . in text mode, all *
forms of commands like \section*
would break unless you changed them to match, which would then break many packages handling section headings... so for ?
\catcode`?\active \def?{!}
but things will break.
Sep 23, 2020 at 13:21
{symbols}{"01}
so will use whatever font is set up as the symbol font, doesn't have to be computer modern. If you have declared an additional font and you want to use that just reference that instead of symbols
Oct 24, 2020 at 12:04
Either
\mathcode`\*=\number\cdot
or
\mathcode`\*=\number\circ
or
\mathcode`\*=\number\bullet
(The \number
isn't really necessary, but it might help for abnormal versions of \circ
or \cdot
or \bullet
.)
\cdot
to be \mathbin{foo}
, using \number
would do nothing good. I'm not sure what “abnormal” definition you're thinking to.
As I pointed out in a comment, redefining the use of *
in the wrong way will prevent you from using star versions of math-mode macros (see partial list below*). For example, making *
active would be the wrong way. However, David C and Don both note that their approaches do not suffer this problem, and I was negligent for not noting the distinction.
While the use of star macros in math mode may be rare, it occurs often enough to warrant avoiding an approach that would use an active *
. Even if you use David's approach, you lose the use of the typeset asterisk in math mode, unless you save it beforehand into a named macro.
An alternative that does not mess with *
in any way would be to redefine \*
. This is a plain-Tex macro known as a "discretionary multiplication sign". I've never used it myself, but the idea is that you can place it between multiplied math terms. Normally, it does nothing, but if the line breaking wants to happen between the two terms, a symbol (equivalent to \times
) is inserted at the line end (in text size). It acts like a mathematical hyphen, but with \times
instead of -
. If you, like me, never use such a construct, then I think it would be safer to redefine \*
rather than *
.
\documentclass{article}
\renewcommand\*{\cdot}
\begin{document}
$ x \* y $
\end{document}
*Examples of star macros include things like \tag*
, \ref*
, \\*
, \matrix*
(and all its variants), \operatorname*
, \alignat*
, just to get started.
*
forms in math mode, so I am not sure I follow your first sentence?
Sep 23, 2020 at 18:15
*
character; they do not change how * is interpreted in text or in syntactical contexts.
Sep 24, 2020 at 9:48
For the sake of completness, version for unicode-math
:
\documentclass{article}
\usepackage{unicode-math}
\AtBeginDocument{\Umathcode`\* = 2 0 "22C5}
\begin{document}
$x*y$
\end{document}
\star
will do, in that case.