I would like to write an expl3 version of the following.
\documentclass{article}
\makeatletter
\def\ie{i.e\@ifnextchar.{}{.\@{} }}
\makeatother
\pagestyle{empty}
\begin{document}
\noindent
\ie Hello\newline
\ie. Hello\newline
\end{document}
I'm aware of the \peek_after:Nw command, but I don't understand how to implement it. In fact, all the \peek_... commands seem to require you to explicitly feed it a token. I seem to have to write a command which takes arguments.
I could try something like:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\eg}{ m }
{
e.g
\str_if_eq_x:nnF { . } { #1 }{.\@{} }
}
\ExplSyntaxOff
\pagestyle{empty}
\begin{document}
\noindent
\eg Hello\newline
\eg. Hello\newline
{\eg} Hello
\end{document}
But there are a couple of sticking points.
First, because \eg is defined to take an argument, it gobbles up the following H in the first instance. \ie doesn't have this problem. (I could get around this by writing something like \str_if_eq_x:nnF { . } { #1 }{.\@{} #1}, but in my real document for which all of this is a greatly reduced MWE, I run into more issues when #1 contains something that's not a character.)
Second, {\eg} creates an error because it's expecting an argument but encounters what it believes are unbalanced parentheses. Again, {\ie} very nicely does not have this issue.
So this approach is really not what I'm looking for.
Here's my attempt at using \peek_after:Nw
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Nn \ae_eg:
{
\peek_after:Nw \ae_test_period:
}
\cs_new:Nn \ae_test_period:
{
\str_if_eq_x:nnF { \l_peek_token } { . } { FALSE }
}
\NewDocumentCommand{\eg}{}
{
e.g \ae_eg:
}
\ExplSyntaxOff
\pagestyle{empty}
\begin{document}
\noindent
\eg. Hello\newline
\eg Hello\newline
\end{document}
But \l_peek_token is never seen to be the same as .