3

I would like to define a command similar to \section that places Greek letters in the right order in an equation. Furthermore I want the option to label a Greek letter to use it later and I would like to give parts of equations names to use them later. e.g.

\begin{equation}
\greekvar + 4 + \frac{1}{N} + \greekvar{specialvar} + d{\int_0^\infty x^2\mathrm{d}x\label{specialintegral}}
\end{equation}
If $\greekref{specialvar}$ is 0 then $d=1$ and $\ref{specialintegral}$ is active.

and the result should be the same as of:

\begin{equation}
\alpha + 4 + \frac{1}{N} + \beta + d\int_0^\infty x^2\mathrm{d}x
\end{equation}
If $\alpha$ is 0 then $d=1$ and $\int_0^\infty x^2\mathrm{d}x$ is active.

If possible I would like to use commands like I proposed. Help appreciated. As far as Greek numbering is considered I found some kind of solution though it does not work in mathmode.

Werner
  • 603,163
apfel
  • 149
  • 5
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Your requirements seem unclear to me. You want \greekvar{specialvar} to expand to \beta in your code, but also want \greekref{specialvar} to expand to \alpha. How is this supposed to work? How would you refer to the \beta? – jub0bs Nov 19 '13 at 23:45
  • In my example I either cannot refer to '\beta' or by the countervalue which would be 2. '\greekvar[specialvar]' would be an alternative. Actually I want the label as an optional parameter. – apfel Nov 20 '13 at 00:00

1 Answers1

3

Nice exercise, but not something I'd recommend.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand\mathgreek[1]{\expandafter\@mathgreek\csname c@#1\endcsname}
\newcommand\@mathgreek[1]{%
  \ifcase#1\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or\zeta\or
  \eta\or\theta\or\kappa\or\lambda\or\mu\or\nu\or\xi\or o\or\pi\or
  \rho\or\sigma\or\tau\or\upsilon\or\chi\or\phi\or\psi\or\omega\else
  \@ctrerror\fi}

\newcounter{greekvars}
\renewcommand\thegreekvars{\mathgreek{greekvars}}

\newcommand\greekvar[1][]{%
  \if\relax\detokenize{#1}\relax
    \stepcounter{greekvars}%
  \else
    \refstepcounter{greekvars}\ltx@label{#1}%
  \fi
  \thegreekvars
}
\makeatother
\newcommand{\greekref}[1]{\ref{#1}}

\newcommand\diff{\mathop{}\!\mathrm{d}}

\begin{document}

\begin{gather}\label{specialintegral}
\greekvar + 4 + \frac{1}{N} + \greekvar[specialvar] + 
c\int_0^\infty x^2 \diff x
\end{gather}
If $\greekref{specialvar}$ is $0$ then $c=1$ and \eqref{specialintegral} is active.
\begin{align}
\greekvar[4]&=1 \label{x}\\
\greekvar[5]&=2 \label{y}
\end{align}
$\greekref{4}$ and $\greekref{5}$ are in \eqref{x} and \eqref{y}

\end{document}

You have to be careful in the placement of \label with equation: it turns out that with amsmath the two labels can't go together. So in case you use a referenced \greekvar you need to use gather instead of equation.

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
  • Hi, I really like your definition of "\greekvar". Although I do not fully understand every detail of it I can somehow figure out what the thought behind it is. I meant something like "\mathpartref{specialintegral}" and it gives the integral or any other maths expression. I cannot see why in your example it is named "beta". – apfel Nov 20 '13 at 00:09
  • @apfel Yes, there's a problem with equation. I'll fix it. – egreg Nov 20 '13 at 00:17
  • Instead of "(1)" the integral itself should be put in there. So I don't want to label the whole equation but rather just a part of it. By refering to this part the part itself, not any number, should be printed. – apfel Nov 20 '13 at 00:58
  • @apfel That's not possible, at least not without a very large work; equation numbers are made just for referring to already stated formulas so that repeating them is not needed. – egreg Nov 20 '13 at 07:29
  • I thought of putting the mathpart in an environment and using a command to mark and print the content somewhere else, not necessarily by using the "\label" but somehow similar. In my opinion such a functionality would be useful not only for mathmode. Should I put this issue in a new question? – apfel Nov 20 '13 at 11:51
  • @apfel I'm quite certain that the problem has already appeared on the site. – egreg Nov 20 '13 at 12:01
  • I figured out "\savebox" for my purpose as LaTeX can repeat stored content like equation numbers the part of a formula needs to be stored first. I refer to http://tex.stackexchange.com/questions/63699/is-it-possible-to-re-insert-a-latex-equation-by-label and close this question now. – apfel Nov 20 '13 at 13:00