0

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.

  • you could copy the xspace package code that does exactly this, apart from the fact that it adds a normal space rather than your kern – David Carlisle Aug 3 at 5:47
  • Thank you, it worked in some instances but I think the issue is that this symbols font doesn't have a lot of spacing around the symbols to begin with so what happens is that for some I get the appropriate amount of spacing with punctuation but then with normal letters its like there is no space in between the symbol and them. – user1738964 Aug 3 at 5:52
1

You could copy the xspace package code that does exactly this, apart from the fact that it adds a normal space rather than your kern.

  • Thank you, it worked in some instances but I think the issue is that this symbols font doesn't have a lot of spacing around the symbols to begin with so what happens is that for some I get the appropriate amount of spacing with punctuation but then with normal letters its like there is no space in between the symbol and them. Is it possible to increase the amount of space xspace adds by default? For instance if the standard space is 1 space, can I up it to 10 if the spaces in this font are really small? – user1738964 Aug 3 at 6:01
  • @user1738964 I meant take xspace.sty copy it to another name and define a command that is like xspace but adds \kern0.25em instead of \space if you place two characters next to each other there is normally no space between them, .25em seems very big for an inter-letter kern it is almost as big as a typical word space (usually around .33 em) but I haven't seen this character. – David Carlisle Aug 3 at 6:07
  • Apologies, that's what I meant it to be - the spacing between two words as the symbol has calligraphy that includes many words. I'm still trying to work out how to get the xspace.sty command into my preamble as I'm working out of overleaf. – user1738964 Aug 3 at 6:27
  • @user1738964 but is this the normal issue that a space after a command is lost, you need to use something like \ in \LaTeX\ is something not \LaTeX is something if you want a word-space after LaTeX, that applies to any command. – David Carlisle Aug 3 at 6:29
  • @user you can use an unchanged xspace just by putting \usepackage{xspace} in your preamble, it is part of every latex distribution. – David Carlisle Aug 3 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.