LyXCustom sorting of Nomenclature entries ?

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
drumsandsail
Posts: 4
Joined: Tue Feb 11, 2014 3:08 pm

Custom sorting of Nomenclature entries ?

Post by drumsandsail »

Hey everyone,

I have a question regarding Nomenclature entries. I'm using the default LyX option to add entries ("Insert -> Nomenclature entry").

My entries are words all in roman letters with some occasional numbers. The default option of LyX gives a "Sort As" field and I would like to sort it in three categories : Chimique, Biologique, and Tampon (literally pardon my french).

When printing the nomenclature in the end, the entries are sorted first using the Bio category, then the chem, then the Temp.

1° What my problem is ?
I would like to have the name of the categories inside the nomenclature. Ie,

Nomenclature
Bio
... bio entries ...

Chem
... chem entries ...

2° What i've managed to find so far.

Using the nomencl package readme (http://tug.ctan.org/tex-archive/macros/ ... omencl.pdf) on page 11 I've found that it's possible to add subgroups.

This would be done by adding something of the nature to the preamble :

Code: Select all

\UsePackage{ifthen}
\renewcommand{\nomgroup}[1]{%
\ifthenelse{\equal{#1}{R}}{\item[\textbf{Variables}
\ifthenelse{\equal{#1}{G}}{\item[\textbf{Constants}
(extracted from the nomencl pdf, where there are only two categories).

3° Where I'm stuck

I really don't understand how those ifthenelse work and how to use them to do what I want.

I've tried

Code: Select all

\UsePackage{ifthen}
\renewcommand{\nomgroup}
\ifthenelse{Biologique}{\item[\textbf{Biologique}
\ifthenelse{Chimique}}{\item[\textbf{Chimique}
But all I'm getting is a bunch of errors which I've added below.


I sense like I'm not using ifthenelse right, but I'm totally new to LyX and reading many different wikis/posts has still not managed to help me yet ...
Attachments
Errors.tiff
Errors.tiff (34.63 KiB) Viewed 12293 times
Last edited by cgnieder on Sun Feb 16, 2014 2:13 pm, edited 1 time in total.

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

Jutschet
Posts: 4
Joined: Thu Jan 09, 2014 3:54 pm

Custom sorting of Nomenclature entries ?

Post by Jutschet »

Hi drumsandsails,
I am not an expert either, but I just faced the same problem some days ago, so I hope I can help you with this.
You are already on the correct way, i.e. the ifthen clauses are the right way. I think you lost some brackets from the example in the readme. Also I am not sure how good it works if you try to take long words for the "if" case. I just tried to use single characters, so in your case I would write:

Code: Select all

\RequirePackage{ifthen}
\renewcommand{\nomgroup}[1]{%
\ifthenelse{\equal{#1}{B}}{\item[\textbf{Biologique}]}{%
\ifthenelse{\equal{#1}{C}}{\item[\textbf{Chemique}]}{%
\ifthenelse{\equal{#1}{T}}{\item[\textbf{Tampon}]}{}}}}
(I am not sure if this is any difference between UsePackage and RequirePackage, and can anyone check if I got the amount of closing brackets correct in the last line?)

Then when putting a nomenclature entry to Lyx, you have to put in the most bottom field "sort as" (I guess, I have the German version) first the character for which list it should be, but this time with a small (!) character (e.g. b) and then add the Abbrevation again.
Example:
abbrevation: MOA
description: My own abbrevation
sort as: bMOA

than MOA will appear in the Biologique list.
I hope this helps (and is correct...)!

Now a little thing about the nomenclature in my own cause:
Can I add an additional line before a new "group"? How would I write this in the ifthen clause? I tried to add a "\newline" before the "\item" in the then clause, but Lyx wouldn't take it. Any ideas?

edit: Ok, found a solution myself. I instead added a "\vspace{1cm}", which worked fine.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Custom sorting of Nomenclature entries ?

Post by cgnieder »

Hi drumsandsail,

welcome to the LaTeX community,

The proposal of the manual can be adapted. (Please not that it's \usepackage that is all lowercase.) I added some comments to the code so it hopefully becomes a little clearer.

Code: Select all

\usepackage{ifthen}
\renewcommand{\nomgroup}[1]{%
  \ifthenelse{\equal{#1}{B}} % if group equals ``B''
    {\item[\textbf{Biology}} % type out ``Biology''
    {%                       % else
      \ifthenelse{\equal{#1}{C}}   % if group equals ``C'' 
        {\item[\textbf{Chemistry}} % type out ``Chemistry''
        {}%                        % else do nothing
    }%
}
I think that you have to assign optional arguments to the \nomenclature commands starting with either B or C (the group letter) for this to work:

Code: Select all

\nomenclature[Bfoo]{foo}{bar}
\nomenclature[Cbar]{bar}{baz}
Regards
site moderator & package author
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Custom sorting of Nomenclature entries ?

Post by cgnieder »

Jutschet wrote:I am not sure if this is any difference between UsePackage and RequirePackage
Yes and no: \RequirePackage is meant to be used in packages (that is, by package authors). \usepackage is meant to be used by users. \usepackage is only allowed after \documentclass and before \begin{document}, i.e., it can only be used in the document's preamble else it throws an error. In the preamble, however, it is equivalent to \RequirePackage.

Regards
site moderator & package author
drumsandsail
Posts: 4
Joined: Tue Feb 11, 2014 3:08 pm

Custom sorting of Nomenclature entries ?

Post by drumsandsail »

Thank you so much for both your help :)

1. Problems solved
Using :

\RequirePackage{ifthen}
\renewcommand{\nomgroup}[1]{%
\ifthenelse{\equal{#1}{B}}{\item[\textbf{Biologique}]}{%
\ifthenelse{\equal{#1}{C}}{\item[\textbf{Chimique}]}{%
\ifthenelse{\equal{#1}{T}}{\item[\textbf{Tampon}]}{}}}}

in the preamble worked as a charm.

2. Next step
Now i'm on to my next challenge. The "Biologique" entries are microorganisms names, which, in theory should come out in italics.

Does anyone have a clue regarding a way to individually format an entry/a group of entries to have them render in italics ?

Also, where exactly did you put the vspace to have the sections spaced out ?

Sorry for not having replied sooner, I must've messed my notifications !!!

And thanks so much for your help already. I mean it, you're really helping me improve in LyX and hopefully one day i'll be able to do this on my own, forum-free !
Jutschet
Posts: 4
Joined: Thu Jan 09, 2014 3:54 pm

Re: Custom sorting of Nomenclature entries ?

Post by Jutschet »

To format your formulars in the nomenclatur you have to use Latex-Code in the Nomenclature entry. I typically made my abbrevations in math-mode ($), which automatically makes them italic:
abbrevation: $MOA$

However this is difficult if you have text-like abbrevations. In that case you probably better use:
abbrevation: \textit{MOA and MOA2}

I don't know if there is also an option to make the abbrevations italic in general, without changing each single entry.

For the "\vspace": I just added it directly before the "\item" command.

Good luck with your further formatting ... and using a forum is a good thing. You learn something and additionally, if others face the same problem they will be happy to find these entries. So don't worry ;) .
drumsandsail
Posts: 4
Joined: Tue Feb 11, 2014 3:08 pm

Re: Custom sorting of Nomenclature entries ?

Post by drumsandsail »

And as always, the \textit trick works as a charm !

I'm so grateful :) :)
Post Reply