This question is related to a previous question of mine Increasing nesting level for parameters and global xparse macros?
I use a modified version of \defsym as given by egreg in this answer to the second question above. However I have the problem that the nomenclature definition fails on occasions, so some symbols are missing. For a MWE check egreg's answer together with the code snippets below.
I do neither understand when exactly it fails nor can I think of a solution how to fix it. It seems to happen when the first use of the symbol is invisible in some way, e.g. \phantom{\Ak} or
\begin{align}
\Uk[j]
\end{align}
The align environment seems to probe the line for the length, therefore the first use is invisible. This can be seen using a \typeout in the symbol definition which will then appear twice in the log.
Inserting one of those snippets above after \begin{document} in egreg's MWE causes the symbols to disappear from the nomenclature.
- I'd like to understand why
\nomenclaturedoes not work e.g. in the following pointless example$\phantom{\nomenclature{$\alpha$}{Foo}}$. I don't understand why writing something to a file fails in this example. - Is there some systematic when it fails?
- How to fix it? Is it possible to check if
\nomenclaturedid successfully write the symbol to the nlo file?

\writecommands will be performed only on shipout. Now my question: is it possible to also set the flag awhatsitobject so that it only gets set when the write did actually take places, something like\write16{\bool_gset_true:c { g_buergi_sym_ \cs_to_str:N #1 _bool }}. The later does not work like that due to missing expansion, I tried some\expandafterbut had no luck so far. – buergi Nov 19 '12 at 08:25\phantom? :) – egreg Nov 19 '12 at 10:08\writecan't work e.g. for symbols in the same math environment, so just forget it. However, if you can imagine a more general solution, let me know but your's is sufficient for my needs. Thanks again. – buergi Nov 19 '12 at 10:45