[Tex/LaTex] Nomenclature Sorting: Correct sorting of math while using groups


I am using LyX to write a report. The nomenclature is divided in groups. Within the "Roman Symbols" group the entries which start with math are sorted before all the non-math entries. See the image at the end of the question.

For example, the entry below should be sorted with the "R"s.


Starting with the second to last entry, the sorting works fine. After many correctly sorted entries (not shown in the image), the last two entries (also not shown) are out of place. They should be sorted with the "D"s. They are written below.



I have tried the solution here:
Make nomenclature sort math correctly

This did not work for me. It might be because I use nomgroups. I do not know. Any ideas? Thanks.

I have written the preamble and the nomenclature entries for the file below. I am rather new to LaTeX so let me know if you need me to post more information.


% Preview source code

%% LyX 2.1.3 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.


% the following is useful when we have the old nomencl.sty package
 breaklinks=true,pdfborder={0 0 0},backref=false,colorlinks=true]
\hypersetup{pdftitle={Title Here},
 pdfauthor={Author Here},
 pdfsubject={Subject Here},
 pdfkeywords={Keywords Here},


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.

%For matlab2tex support

%For nomenclature
  \ifstrequal{#1}{R}{Roman Symbols}{%
  \ifstrequal{#1}{G}{Greek Symbols}{%
  \ifstrequal{#1}{X}{Other Symbols}{}}}}}]%



Nomenclature Entries:


%Roman Symbols (Sort as R)

%With math








\nomenclature[R]{$\left\Vert u_{i}\right\Vert $}{Ve}


\nomenclature[R]{$\left\Vert \overline{u}_{i}\right\Vert $}{Ave}




%Without Math



enter image description here

Best Answer

Nomenclature package pastes your prefix and entry to form the sorting label. Since $\Delta$ starts with backslash, makeindex sorts the entry \nomenclature[R]{${\Delta}Z_0$}{Lig} as R${\Delta$}, and the entry \nomenclature[R]{$D$}{Letter D} as R$D$. If you want \Delta to be sorted as D, use \nomenclature[R$D$]{${\Delta}Z_0$}{Lig} as well as \nomenclature[R$D$]{$\mathbf{C}$}{DM}, \nomenclature[R$A$]{$\tilde{A}$}{DM} etc.

In general if your math entry does not start with a letter, use R$LETTER$ as prefix.