I have been reading answers to latex questions for the past while in order to address an issue I am having. I am using a font that contains symbols and mapping the symbols to a latex command. For this MWE you could use any font with symbols that might not be found in the latin character set. Here is the one I am using (I just changed the filename to Symbols.otf), and here is some documentation for it, including XeLaTeX commands. This part works fine:
\documentclass[10pt,twoside]{book}
\makeatletter
\newfontface\honourific[Path = ./fonts/]{Symbols.otf}
\newcommand{\hn}[1]{{\honourific\XeTeXglyph #1}}
\newcommand{\RahimahumuLlah}{{\large\hn{83}\kern0.25em}}
\begin{document}
...and a similar statement has been reported as being the view of Imām Mālik Ibn Anas \RahimahumuLlah.
\begin{document}
Now when I try to use \firstcommand in my typesetting, it works, however when there is a period, comma, colon, semi-colon or other punctuation mark, the symbol might have a lot more or a lot less space than needed after it. This is why I set the default kerning to 0.25em which works great for most situations. What I want to do is have it setup such that it checks to see if there is an applicable punctuation mark right after the symbol (period, comma, colon...) and if so, it applies 0.05em if kerning instead.
I came across some discussions of the @ifnextchar command, particularly this thread which had started in this forum post. I tried to implement the forum poster's final answer in my code but what I found was that it was not evaluating either the true of false conditions.
If you could offer some clarification as to how to implement this or any other method of conditional kerning I would be greatly appreciative.
Thank you
Edit:
Ok I've done some testing and may have narrowed down the problem. Using xspace doesn't work and neither does manually running through conditionals to detect punctuation. I used this code to try and find where my issue was:
\makeatletter
\newcommand{\punctuationcheck}{%
\@ifnextchar){parens\relax}{%
\@ifnextchar]{square bracket\relax}{%
\@ifnextchar.{fullstop\relax}{%
\@ifnextchar,{comma\relax}{space
}%
}%
}%
}%
}
\makeatother
When I run this code, it doesn't detect a comma and instead just inserts the word 'space', whether or not a space actually comes after the comma or not. I had a look at the answer here and it noted using {} after commands to preserve spaces as needed. I tried this and it worked. The issue now is how can I force LaTeX to append a {} after each my custom commands so I don't have to remember to do when I am typing out my document?
Edit 2: Resolved
So it turns out where you put the \xspace command in the definition really matters.
First instance:
\newcommand{\RahimahumuLlah}{{\large\hn{83}\xspace}}
I wasn't seeing the command working. I moved the command to right before the last brace:
\newcommand{\RahimahumuLlah}{{\large\hn{83}}\xspace}
And it works.