回調替換活動角色

回調替換活動角色

使用 LuaLaTeX、TeXlive 2024、Linux。

編輯:正如 David 所寫,在接受的答案中,這不需要 Lua 回調。但我會留下這個問題,因為其他用戶可能會嘗試做類似的事情,而不需要預先存在的文字定義"

我的申請涉及文本(不是數學或圖表)。我與人工編輯器交換純文字文件,偶爾"會出現雜亂的情況。 TeX 處理它們的方式"與文字處理程式(由編輯器使用)處理它們的方式不同。

TeX 連字始終設定"為右側雙大引號。不是我想要的。雖然我可以"tlig清單中刪除,但這還不夠。我想做的就是每當"遇到時就寫一則訊息。然後,將其留在"原處(不要捲曲)。

"我可以透過創建一個活躍的角色來寫訊息。但這樣我就不能離開 "原地,因為它會跑到無限大。

我可以用我為此目的創建的不同 Unicode 字元替換 active ",它是".這(幾乎)解決了問題:我可以寫訊息,當列印到紙上時,我可以看到"那裡。但由於替代字元實際上並不是"機器人 PDF 檢查器,因此可能會對其進行標記。這超出了 TeX 的範圍。

查看各個部分的程式碼,texmf-dist/tex/luatex我發現有一個something.sub方法,允許透過回調進行字形替換。聽起來像我需要的。唉,我還不是一個程式設計師,無法辨別如何使用它。

微量元素:

\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}

注意:在文件正文中,我不需要"babel 或 polyglossia 捷徑、\char"HHHH巨集或數學。

儘管之前已經詢問過使用 LuaLaTeX 進行字元替換,但現有的問題似乎都無法解決活動字元的問題。

答案1

LaTeX 提供了存取直引號的命令

在此輸入影像描述

\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}

相關內容