[Edit 1] originally titled "can't understand why this simple macro causes complex error"
[original post] I've written a book, and now I'm trying to produce the e-book using tex4ht. Adapting this post, I introduced the following macro:
\newcommand{\gpifpdf}[2]{\ifx\HCode\UnDef{#1}\else{#2}\fi}
Which should return the first argument when producing the pdf file, and the second when using mk4ht to produce the html file.
Here is my m(n)we:
\documentclass[10pt]{book}
\usepackage{hyperref}
\newcommand{\gpifpdf}[2]{\ifx\HCode\UnDef{#1}\else{#2}\fi}
\gpifpdf{
\usepackage{fontspec}
}{
\hypersetup{tex4ht}
}
\begin{document}
\gpifpdf{this is pdf text}{this is HTML text}
\end{document}
mk4ht produces an html file which displays "this is HTML text." But using Latexian to generate a pdf generates the following error:
Undefined control sequence.
\clist_if_empty:NF #1->\if_meaning:w
#1\c_empty_tl \prg_return_true: \else: \prg_return_false: \fi: \c_zero {}
l.9 \begin{document}
HOWEVER, when I comment out \usepackage{fontspec}, it works perfectly, producing a pdf reading "this is pdf text," so the macro seems to work correctly in the document body. When I leave in the \usepackage{fontspec}, and comment out the line before and the 3 lines afterwards (lines 4, 6, 7, and 8) it also produces the pdf just fine.
In other words: the macro seems to function correctly, and when I do what the macro is supposed to do by hand, everything works, but when I try to get the macro to do it, it doesn't.
I just upgrade to MacTeX 2014 from 2013 (so TeXlive 2014), and the problem continues. I am using Latexian, with the XeTeX option.
{#1}and{#2}acting as a group? You can remove them.\ifx) which could be good for future users that need to search for this.