[latex3-commits] [git/LaTeX3-latex3-latex2e] develop: Access raw glyphs in LuaTeX without reloading font (7c99084f)
Marcel Fabian Krüger
tex at 2krueger.de
Sat Jul 4 14:08:29 CEST 2020
Repository : https://github.com/latex3/latex2e
On branch : develop
Link : https://github.com/latex3/latex2e/commit/7c99084f60cc0fd6a9cd74f16d555c36fdad151f
>---------------------------------------------------------------
commit 7c99084f60cc0fd6a9cd74f16d555c36fdad151f
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sat Jul 4 13:56:31 2020 +0200
Access raw glyphs in LuaTeX without reloading font
Closes #165.
>---------------------------------------------------------------
7c99084f60cc0fd6a9cd74f16d555c36fdad151f
base/changes.txt | 15 +++--
base/doc/ltnews32.tex | 15 +++++
base/ltoutenc.dtx | 84 ++++++++++++++++++++-------
base/testfiles-TU/tu-asciiquotes01.luatex.tlg | 12 ++--
base/testfiles-TU/tu-textcomp-003.luatex.tlg | 4 +-
base/testfiles-TU/tu-textcomp-004.luatex.tlg | 4 +-
6 files changed, 98 insertions(+), 36 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index 1015ddbf..a52a672d 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -6,6 +6,11 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
================================================================================
+2020-07-04 Marcel Krüger <Marcel.Krueger at latex-project.org>
+
+ * ltoutenc.dtx:
+ Suppress tlig ligatures in LuaTeX without font reloading (gh/165)
+
2020-06-15 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
* doc.dtx (subsection{Macros surrounding the `definition parts'}):
@@ -36,7 +41,7 @@ are not part of the distribution.
2020-06-04 Marcel Krüger <Marcel.Krueger at latex-project.org>
- * format.ins: Load ltluatex.dtx before ltdefns.dtx
+ * format.ins: Load ltluatex.dtx before ltdefns.dtx
2020-05-31 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
@@ -62,8 +67,8 @@ are not part of the distribution.
2020-05-11 Marcel Krüger <Marcel.Krueger at latex-project.org>
- * ltdefns.dtx:
- Use primitive \- with LuaTeX
+ * ltdefns.dtx:
+ Use primitive \- with LuaTeX
2020-05-07 Ulrike Fischer <Ulrike.Fischer at latex-project.org>
@@ -72,8 +77,8 @@ are not part of the distribution.
2020-05-06 Marcel Krüger <Marcel.Krueger at latex-project.org>
- * ltspace.dtx:
- Make Unicode softhyphen U+00AD active and defined as \-.
+ * ltspace.dtx:
+ Make Unicode softhyphen U+00AD active and defined as \-.
2020-05-02 Johannes Braams <Johannes.Braams at latex-project.org>
diff --git a/base/doc/ltnews32.tex b/base/doc/ltnews32.tex
index ab63436f..57670bf3 100644
--- a/base/doc/ltnews32.tex
+++ b/base/doc/ltnews32.tex
@@ -519,6 +519,21 @@ command name(s) & math & text\\\hline
+\subsection{Access raw glyphs in \LuaTeX\ without reloading fonts}
+
+\LaTeX's definitions for \cs{textquotesingle}, \cs{textasciigrave}, and
+\cs{textquotedbl} for the TU encoding in \LuaTeX\ need special handling to
+stop the shaper from replacing these characters with curly quotes.
+This used to be done by reloading the current font without the \texttt{tlig}
+feature, but that came with multiple disadvantages: It behaves different
+than the corresponding \XeTeX\ code and it is not very efficient.
+This code has now been replaced with a implementation which injects a
+protected glyph nodes which is not affected by font shaping.
+%
+\githubissue{165}
+
+
+
\section{Changes to packages in the \pkg{graphics} category}
\subsection{Generate a warning if existing color definition is changed}
diff --git a/base/ltoutenc.dtx b/base/ltoutenc.dtx
index 8831b565..dd725585 100644
--- a/base/ltoutenc.dtx
+++ b/base/ltoutenc.dtx
@@ -44,7 +44,7 @@
%<*driver>
% \fi
\ProvidesFile{ltoutenc.dtx}
- [2020/04/22 v2.0p LaTeX Kernel (font encodings)]
+ [2021/07/04 v2.0q LaTeX Kernel (font encodings)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltoutenc.dtx}
@@ -2869,28 +2869,70 @@
% \end{macrocode}
%
% LuaTeX.
+% For Lua\TeX~1.10+, define a Lua function to disable any handing by the font code.
+% Otherwise we reload the font without TeX ligatures.
+% \changes{v2.0q}{2020/07/04}{%
+% Implement \cs{remove at tlig} in Lua\TeX without font reloading}
% \begin{macrocode}
\def\UnicodeFontTeXLigatures{+tlig;}
-% \end{macrocode}
-%
-% \begin{macrocode}
- \def\reserved at a#1{%
- \def\@remove at tlig##1{\@remove at tlig@##1\@nil#1\@nil\relax}
- \def\@remove at tlig@##1#1{\@remove at tlig@@##1}}
- \edef\reserved at b{\detokenize{+tlig;}}
- \expandafter\reserved at a\expandafter{\reserved at b}
- \def\@remove at tlig@@#1\@nil#2\relax{#1}
-% \end{macrocode}
-%
-% \begin{macrocode}
- \def\remove at tlig#1{%
- \begingroup
- \font\remove at tlig
- \expandafter\@remove at tlig\expandafter{\fontname\font}%
- \remove at tlig
- \char#1\relax
- \endgroup
- }
+ \ifnum\luatexversion<110
+% \end{macrocode}
+%
+% \begin{macrocode}
+ \def\reserved at a#1{%
+ \def\@remove at tlig##1{\@remove at tlig@##1\@nil#1\@nil\relax}
+ \def\@remove at tlig@##1#1{\@remove at tlig@@##1}}
+ \edef\reserved at b{\detokenize{+tlig;}}
+ \expandafter\reserved at a\expandafter{\reserved at b}
+ \def\@remove at tlig@@#1\@nil#2\relax{#1}
+% \end{macrocode}
+%
+% \begin{macrocode}
+ \def\remove at tlig#1{%
+ \begingroup
+ \font\remove at tlig
+ \expandafter\@remove at tlig\expandafter{\fontname\font}%
+ \remove at tlig
+ \char#1\relax
+ \endgroup
+ }
+ \else
+ \newluafunction\@remove at tlig@@@@
+% \end{macrocode}
+% We are in the format and Lua functions can not be dumped, so we have to repeat
+% the code during |\everyjob|. Therefore we first define a helper to both execute
+% some code and same it for |\everyjob|:
+% \begin{macrocode}
+ \def\now at and@everyjob#1{\toksapp\everyjob{#1}#1}
+% \end{macrocode}
+% Now we can define the function. Mostly we just have to insert a protected glyph
+% node, which is a glyph node with subtype 256. But we have to keep track of the
+% current mode to avoid inserting the glyph into a vlist.
+% \begin{macrocode}
+ \now at and@everyjob{\directlua{
+ local rawchar_func = token.create'@remove at tlig@@@@'.mode
+ local forcehmode = tex.forcehmode
+ local put_next = token.put_next
+ local glyph_id = node.id'glyph'
+ local rawchar_token = token.new(rawchar_func, token.command_id'lua_call')
+ lua.get_functions_table()[rawchar_func] = function()
+ local mode = tex.nest.top.mode
+ if mode == 1 or mode == -1 then
+ put_next(rawchar_token)
+ return forcehmode(true)
+ end
+ local n = node.new(glyph_id, 256)
+ n.font = font.current()
+ n.char = token.scan_int()
+ return node.write(n)
+ end
+ token.set_lua('@remove at tlig@@@', rawchar_func, 'global', 'protected')
+ }}
+% \end{macrocode}
+% Now \verb+\remove at tlig+ can be implemented almost as in XeTeX.
+% \begin{macrocode}
+ \def\remove at tlig#1{\@remove at tlig@@@#1\relax}
+ \fi
% \end{macrocode}
%
% \begin{macrocode}
diff --git a/base/testfiles-TU/tu-asciiquotes01.luatex.tlg b/base/testfiles-TU/tu-asciiquotes01.luatex.tlg
index 8b312c03..6bd0912e 100644
--- a/base/testfiles-TU/tu-asciiquotes01.luatex.tlg
+++ b/base/testfiles-TU/tu-asciiquotes01.luatex.tlg
@@ -2,22 +2,22 @@ This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
> \box...=
\hbox(7.05+0.0)x10.56, direction TLT
-.\remove at tlig '
+.\TU/lmr/m/n/10 '
.\TU/lmr/m/n/10 1
-.\remove at tlig '
+.\TU/lmr/m/n/10 '
! OK.
l. ...\test{\textquotesingle 1\textquotesingle}
> \box...=
\hbox(7.05+0.0)x12.48001, direction TLT
-.\remove at tlig "
+.\TU/lmr/m/n/10 "
.\TU/lmr/m/n/10 2
-.\remove at tlig "
+.\TU/lmr/m/n/10 "
! OK.
l. ...\test{\textquotedbl 2\textquotedbl}
> \box...=
\hbox(6.98+0.22)x15.0, direction TLT
-.\remove at tlig `
+.\TU/lmr/m/n/10 `
.\TU/lmr/m/n/10 3
-.\remove at tlig `
+.\TU/lmr/m/n/10 `
! OK.
l. ...\test{\textasciigrave 3\textasciigrave}
diff --git a/base/testfiles-TU/tu-textcomp-003.luatex.tlg b/base/testfiles-TU/tu-textcomp-003.luatex.tlg
index fb8ebb04..0b8cf063 100644
--- a/base/testfiles-TU/tu-textcomp-003.luatex.tlg
+++ b/base/testfiles-TU/tu-textcomp-003.luatex.tlg
@@ -346,7 +346,7 @@ ne \ETC.}
....\TU/lmtt/m/n/10 v
....\TU/lmtt/m/n/10 e
....\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
-....\remove at tlig `
+....\TU/lmr/m/n/10 `
....\penalty 10000
....\glue 0.0 plus 1.0fil
....\penalty -10000
@@ -1598,7 +1598,7 @@ Completed box being shipped out [2]
....\TU/lmtt/m/n/10 l
....\TU/lmtt/m/n/10 e
....\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
-....\remove at tlig '
+....\TU/lmr/m/n/10 '
....\penalty 10000
....\glue 0.0 plus 1.0fil
....\penalty -10000
diff --git a/base/testfiles-TU/tu-textcomp-004.luatex.tlg b/base/testfiles-TU/tu-textcomp-004.luatex.tlg
index daaf7492..4de84824 100644
--- a/base/testfiles-TU/tu-textcomp-004.luatex.tlg
+++ b/base/testfiles-TU/tu-textcomp-004.luatex.tlg
@@ -313,7 +313,7 @@ ne \ETC.}
....\TU/lmtt/m/n/10 v
....\TU/lmtt/m/n/10 e
....\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
-....\remove at tlig `
+....\TU/lmr/m/n/10 `
....\penalty 10000
....\glue 0.0 plus 1.0fil
....\penalty -10000
@@ -1565,7 +1565,7 @@ Completed box being shipped out [2]
....\TU/lmtt/m/n/10 l
....\TU/lmtt/m/n/10 e
....\glue(\spaceskip) 3.33 plus 1.665 minus 1.11
-....\remove at tlig '
+....\TU/lmr/m/n/10 '
....\penalty 10000
....\glue 0.0 plus 1.0fil
....\penalty -10000
More information about the latex3-commits
mailing list.