Generalnomencl | Renew Commands

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

nomencl | Renew Commands

Post by ggyyree »

I use 'nomencl' package to create a Nomenclature for my thesis.

I would like to use renewcommand to show my symbols, which have been firstly used in one equation with the page information, e.g.,

Code: Select all

\renewcommand{\eqdeclaration}[1]{.~(First used in Equation #1}%
\renewcommand{\pagedeclaration}[1]{~on page #1)} 
And I get this for symbol 'C':
C Relevant temp. (First used in Equation 1.2 on page 18).

However, some symbols haven't been used in any equation. Then it shows:
a A constant. on page 118).
which is wrong becuase I need another definition for \pagedeclaration like:

Code: Select all

\renewcommand{\pagedeclaration}[1]{.~(First appears on page #1)}
to display
a A constant. (First appears on page 118).

Because I didn't call these two functions explicitly, the 'nomencl' package uses them somehow. I don't know how to define two \pagedeclaration. Like this pseudo-code:

Code: Select all

if (\eqdeclaration defined)
{
  \renewcommand{\pagedeclaration}[1]{~on page #1)}
}
else
{
  \renewcommand{\pagedeclaration}[1]{.~(First appears on page #1)}
}

Any ideas? Thanks a lot!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

nomencl | Renew Commands

Post by cgnieder »

Luckily for us (or more precisely you) nomencl defines internal ifs we can use:

Code: Select all

\documentclass{article}
\usepackage{nomencl}

\makeatletter
\renewcommand{\eqdeclaration}[1]{%
  .~(First used in Equation #1\if@printpageref\else )\fi}
\renewcommand{\pagedeclaration}[1]{%
  \if@printeqref ~on page #1)\else .~(First appears on page #1)\fi}
\makeatother

\makenomenclature
\begin{document}

\section*{Main equations}
\begin{equation}
a=\frac{N}{A}
\end{equation}%
\nomenclature{$a$}{The number of angels per unit area\nomrefeqpage}%
\nomenclature{$N$}{The number of angels per needle point\nomrefeq}% 
\nomenclature{$A$}{The area of the needle point\nomrefeq\nomrefpage}%
The equation $\sigma = m a$%
\nomenclature{$\sigma$}{The total mass of angels per unit area}%
\nomenclature{$m$}{The mass of one angel\nomrefpage}
follows easily.

\printnomenclature

\end{document}
Regards

PS: next time it would be nice if you provided a minimal example so I (or any other helper) don't have to build one on my own. Easy enough this time I could copy & paste one from the nomencl documentation, but still...
site moderator & package author
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

nomencl | Renew Commands

Post by ggyyree »

Thanks so much for your reply! And it works now! :mrgreen:

Sorry about what I post that didn't include an example. I will do it next time.

Could you please explain about the codes?

Code: Select all

\makeatletter
\renewcommand{\eqdeclaration}[1]{%
  .~(First used in Equation #1\if@printpageref\else )\fi}
\renewcommand{\pagedeclaration}[1]{%
  \if@printeqref ~on page #1)\else .~(First appears on page #1)\fi}
\makeatother

Where can I find the definition of @printpageref and @printeqref? How did you find them? Thanks.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

nomencl | Renew Commands

Post by cgnieder »

Are you familiar with TeX's \if<> ... \else ... \fi constructs?

If you take a look in "nomencl.sty" in lines 37 and 38 it reads:

Code: Select all

\newif\if@printeqref
\newif\if@printpageref
which means that two new booleans are defined.

It works like this. Define boolean:

Code: Select all

\newif\if<myif>
which then can be used. Set true or false:

Code: Select all

\<myif>true
\<myif>false
Do something depending on the current state:

Code: Select all

\if<myif> do when true \fi
\if<myif> true \else false\fi
Lines 177 to 182 in "nomenc.sty" define the commands used in a \nomenclature:

Code: Select all

\def\nomrefeq{\@printeqreftrue}
\def\nomrefpage{\@printpagereftrue}
\def\nomrefeqpage{\@printeqreftrue\@printpagereftrue}
\def\nomnorefeq{\@printeqreffalse}
\def\nomnorefpage{\@printpagereffalse}
\def\nomnorefeqpage{\@printeqreffalse\@printpagereffalse}
You can see that it sets these booleans true or false.

The redefinition now use these booleans to do different things depending on the state of these booleans:

Code: Select all

\makeatletter% make @ a letter so it can be part of a command name
\renewcommand{\eqdeclaration}[1]{%
  .~(First used in Equation #1% write this always
  \if@printpageref\else )\fi}% and close the bracket if _no_ pageref follows
\renewcommand{\pagedeclaration}[1]{%
  \if@printeqref ~on page #1)% if eqref is printed use "~on page #1)"
  \else .~(First appears on page #1)\fi}% else use ".~(First appears on page #1))"
\makeatother% make @ other again
site moderator & package author
ggyyree
Posts: 21
Joined: Mon Sep 15, 2008 6:32 pm

Re: nomencl | Renew Commands

Post by ggyyree »

Crystal clear! Thanks very much and have a good night! :lol:
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: nomencl | Renew Commands

Post by Stefan Kottwitz »

Hi Clemens,

thank you for the good explanation!
Your contributions are very valuable, and I really enjoy reading your posts.

Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Re: nomencl | Renew Commands

Post by cgnieder »

As long as I keep enjoying the helping (and the trouble-shooting, of course!) there'll be more of them ;) Thanks back!
site moderator & package author
Post Reply