3

See this for an example of how replacing * with \cdot would work.

I want to do the same type of thing but only within an environment. For example:

\newenvironment{starmultiply}
{
% Something here...
}
{
% Undo previous effect
}

Another good usage would be to replace < and > with \langle and \rangle.

I don't always want to do this throughout the document, so DeclareMathSymbol can't be used (it is preamble only). Also,

\newenvironment{starmultiply}
{
\mathcode`\*="8000 %
{\catcode`\*=\active\gdef*{\cdot}}
}
{
% Undo previous effect
}

Doesn't seem to work. I get "Undefined control sequence" errors. Is there any solution which isn't super gross?

1 Answers1

5

You can simply change the math code of *. Doing \gdef* is not recommended and wouldn't work like that anyway; there are better methods to do the definition only locally. See the extended code below.

\documentclass{article}
\usepackage{amsmath}

\newenvironment{starmultiply} {\mathcode`*=\cdot\ignorespaces} {\ignorespacesafterend}

\begin{document}

This is a standard multiplication $a\cdot b$

\begin{starmultiply} This is a nonstandard multiplication $a*b$ \end{starmultiply}

\end{document}

enter image description here

For \langle and \rangle it's a bit more complicated:

\documentclass{article}
\usepackage{amsmath}

\newenvironment{starmultiply} {% \mathcode*=\cdot \mathcode<="8000 \mathcode&gt;=&quot;8000 \begingroup\lccode~=&lt; \lowercase{\endgroup\let~}\langle \begingroup\lccode~=`> \lowercase{\endgroup\let~}\rangle \ignorespaces} {\ignorespacesafterend}

\begin{document}

This is a standard multiplication $\langle a\cdot b\rangle$

\begin{starmultiply} This is a nonstandard multiplication $<a*b>$ \end{starmultiply}

\end{document}

enter image description here

egreg
  • 1,121,712