开发者

How do I use \renewcommand to get BACK my greek letters?

I'm a LaTeX newbie, but I've been doing my homework, and now I have a question that I can't seem to find the answer to. I create the definition of an equation, let's just say it's this one:

The potential is characterized by a length $\sigma$ and an energy $\epsilon$.

In reality, this equation is more complex, which is why I wanted to try a shortcut. If my equation were this simplistic, I wouldn't try my substitution technique. I use the \renewcommand to save me some time:

\renewcommand{\sigma}{1}

And this works fabulously and will replace all instances of sigma with 1. Unfortunately though, since \sigma has a global scope, I need to reset it. I tried a couple different ways:

Attempt 1: -deadlock due to circular reference?

\newcommand{\holdsigma}{\sigma}
\renewcommand{\sigma}{1}
The potential is characterized by a length $\sigma$ and an energy $\epsilon$.
\renewcommand{\sigma}{\holdsigma}

I would think to reset the command, it should look something like this:

\renewcommand{\sigma}{\greek{\sigma}}

but that obviously hasn't worked out for me.

Any idea 开发者_如何学编程about how the greek letters are originally defined in the language?


I have to admit that I don't understand why you want to do what you're asking, but this should work:

\documentclass{article}
\begin{document}

Before redefinition, \verb|\sigma| looks like $\sigma$.

% Copy the current definition of \sigma to \oldsigma
\let\oldsigma\sigma

% Redefine \sigma to be '1'
\renewcommand{\sigma}{1}

After redefinition, \verb|\sigma| looks like $\sigma$.

You can still use \verb|\oldsigma| if you want to use the original definition $\oldsigma$.

% Restore the original definition of \sigma
\let\sigma\oldsigma

Now \verb|\sigma| is back to its normal appearance $\sigma$.

\end{document}


To find out how \sigma or any other command is originally defined, you can use \show\sigma. (The answer is that \sigma is defined as \mathchar"11B.) You can type this either in your document itself — compilation will pause and you can type Enter after reading the reply — or you can type this in TeX/LaTeX's interactive mode.

Example with a document:

\documentclass{article}
\begin{document}
What is $\sigma$?          % Prints "What is σ" in the DVI/PS/PDF.
\show\sigma                % Prints "> \sigma=\mathchar"11B." in the compilation.
Now that we know, let us redefine it.
\renewcommand{\sigma}{1}
Now it is: $\sigma$.       % Prints "Now it is: 1." in the DVI/PS/PDF.
OK, let's go back.
\renewcommand{\sigma}{\mathchar"11B}
We again have: $\sigma$.   %Prints "We again have: σ." in the DVI/PS/PDF.
\end{document}

Or else at the command prompt, type latex, then type \relax, then type \show\sigma, read what it says, then type x to exit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜