2

Using LuaLaTeX, TeXlive 2024, Linux.

EDIT: As David wrote, in the accepted answer, this does not require Lua callback. But I will leave the question, because other users may try to do something similar, without the pre-existing text definition for ".

My application involves text (not math or diagrams). I exchange plain text files with a human editor, and occasionally a stray " gets in. The double quotes are widely used in English dialogue. The way that TeX treats " is different from the way that a word processor (used by the editor) treats them.

TeX ligatures always set " to right-side double curly quotes. Not what I want. Although I can remove " from the tlig list, that is not enough. What I want to do is write a message whenever " is encountered. Then, leave the " in-place (not curly).

I can write the message, by making " an active character. But then I cannot leave the " in-place, because it runs to infinity.

I can substitute the active " with a different Unicode character, created by me for that purpose, which is a copy of ". This solves the problem (almost): I can write the message, and when printed to paper, I see " there. But because the substitute character is not actually " a robot PDF-inspector may flag it. That is outside the scope of TeX.

Looking at code in various parts of texmf-dist/tex/luatex I see that there is a something.sub method, that allows glyph substitution via callback. Sound like what I need. Alas, I am not enough of a programmer to discern how to use it.

MWE:

\documentclass{article} % compile with lualatex
\usepackage{fontspec}
\begin{document}
\catcode`\"=13 % straight double quotes now active.
\def"{\typeout{EEEEEK}º} % message, and subtitute with something else.
Hello, "World."\par
% I used the degree symbol as substitute character, because they have
% similar metrics in Latin Modern Roman. In my own usage, I use a different
% character, specifically created for the purpose (custom font).
% That character is identical to " but at a different Unicode location.
% At this point I would like to use a Lua callback for the finished paragraph,
% and revert the substitute back to ".
I said, "Hello," previously.
% Do it again.
\end{document}

Note: In the document body, I do not need " for babel or polyglossia shortcuts, or for \char"HHHH macros, or for math.

Although the use of LuaLaTeX for character substitution has been asked before, none of the existing questions appears to address the issue with an active character.

1 Answer 1

2

LaTeX provides a command to access the straight quotes

enter image description here

\documentclass{article} % compile with lualatex
\usepackage{fontspec}
\begin{document}
\catcode`\"=13 % straight double quotes now active.
\def"{\typeout{EEEEEK}\textquotedbl} % message, and subtitute with something else.
Hello, "World."\par
% I used the degree symbol as substitute character, because they have
% similar metrics in Latin Modern Roman. In my own usage, I use a different
% character, specifically created for the purpose (custom font).
% That character is identical to " but at a different Unicode location.
% At this point I would like to use a Lua callback for the finished paragraph,
% and revert the substitute back to ".
I said, "Hello," previously.
% Do it again.
\end{document}
3
  • 1
    So simple! Once in a while, I ask a question expecting a complex answer, but it is simple; other times, I expect a simple answer, but it is not. Another good reason why I write fiction instead of programming. :)
    – user287367
    Apr 12 at 20:26
  • I see that the gist of my question was already noted, by Ulrike Fishers, over at the relevant GiutHub site, years ago: github.com/latex3/luaotfload/issues/14
    – user287367
    Apr 13 at 18:34
  • 1
    @rallg "% (Based on David Carlisle's code from the original issue)" no idea what that was about but I assume it was good code:-) Apr 13 at 18:40

You must log in to answer this question.