I have a semantic annotation \monster
to annotate mentions of monsters so that they are indexed:
\newcommand{\indexMonster}[1]{\index{#1}}
\newcommand{\monster}[1]{#1\indexMonster{#1}}
Now, most of the monsters mentions are in plural but some are not. I would like the index entries to be in singular. So I am looking for a way to strip the last character of the \monster
argument if it is 's'.
Best Answer
This solution uses
xstring
. Since there are some terrible monsters named albatross which are intesly feared, and you of course will be writing a lot about, I have also made a warning system for when the names of monsters have been changed. You can of course drop this if you feel like. If you want to override the test for monsters ending ins
, simply add braces around your monster, like in the example below.Output
Code
Second solution
Here is my attempt at this with
expl3
. I just did the text-replacement, not the indexing, but that should be trivial.