This is a follow-up question to Numbering of compounds in the order it appears in the schemes (bpchem or similar)

I had the same problem of the author of the previous question and I tried the solution proposed by @Werner: it works almost perfectly. Anyway, there is a minor issue I would like to solve (but most of all I would like to understand why it doesn't work as I expect).

Here is my code:


\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro


Compound number \CNref{comp1}, compound number \CNref{comp2}.

It's almost the same code as the previos question, there is only a difference: the command \schemeref is used here without the optional argument [TMPX]. If I add the optional argument (which I don't need since my schemes have the standard label TMP1, TMP2, ecc...) everything works fine: the output pdf has correct compound numbering in the schemes and correct compound referencing in the test. If I drop the option argument the referencing in the text continues to work fine (the command \CNref is substituted with the number of the corresponding compound) but the labels TMP1, TMP2, ecc... in the schemes are no more substituted with the expected number! They are left as they are, TMP1, TMP2...

Here an image to clarify: labels not sbustituted

I was wondering why the redefinition of \schemeref doesn't handle properly the empty optional argument... No errors or warnings from Latex.

I am a new italian user of StackEschange, so forgive any mistake I made!

Thank you for any help.

  • This won't work: as schemes can float, you have to set up your labelling before the float (outside the scheme).
    – Joseph Wright
    Commented Jul 24, 2015 at 8:02
  • Do you mean that I need to declare the compounds out of the floating scheme environment?
    – Rackbox
    Commented Jul 24, 2015 at 8:06
  • @Rackbox Yes, much the same as citations or any other moving references
    – Joseph Wright
    Commented Jul 24, 2015 at 16:00
  • @JosephWright: why? How do you explain the fact that \schemeref[TMP1]{comp1} works perfectly while \schemeref{comp1} doesn't?
    – Rackbox
    Commented Jul 24, 2015 at 20:41
  • 1
    @Rackbox you need to test if #1 is blank and if it is use \oldschemeref without optional argument, I guess. Otherwise you're probably telling \oldschemeref to replace an empty string instead of the default one…
    – cgnieder
    Commented Jul 31, 2015 at 15:17

1 Answer 1


You need to test if the optional argument is blank and call \oldschemeref without optional argument if it is. You can do this in a variety of ways. Manually:


Load etoolbox and use \ifblank:


Use xparse:


Or … any number of other ways.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .