This is a follow up to my earlier question here: Detect catcode of next character?
What I want to do: Count the number of "
used in the document body. I am not using "
for purposes such as math, babel shortcuts, or Unicode characters. Just dialog quotations (fiction writing, English).
I hunted around various packages, and see that polyglossia
has gloss-dutch
, which sets some accented characters to be active. This is done withing a \def
macro. It looked like just what I need. To my surprise, it works when I write the code not within a \def
, but fails when I write the code within a \def
(inaccessible). MWE, which works as-is:
\documentclass{article} % Compile using lualatex.
\usepackage{fontspec} % Less-minimal exaple would need this.
\defaultfontfeatures{} % Reset, to avoid tlig for this MWE.
\newcounter{dblq}
\def\shazam{} % Placeholder.
% To see the problem, uncomment/comment:
% Uncomment these 4 lines:
%\def\shazam{
% \catcode`\"=13
% \def "{”\stepcounter{dblq}}
%}
% And apply comment to these two lines:
\catcode`\"=13
\def "{”\stepcounter{dblq}}
\begin{document}
\shazam
"What in the world," he asked, "is happening here?"
\typeout{DBLQ=\arabic{dblq}}
\end{document}
Reason for lualatex
is that I use only utf-8 with fontspec
.
I have tried various random changes such as removing space, using \let
, etc. No joy. Also fails with \AtBeginDocument
.
\AtBeginDocument
) and the problem also arises there. But if I change the catcode outside the hook, it works. But I do not know if that would cause potential problems, with other items loaded at the hook.