| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: tagpdf-space.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 2019-2026 Ulrike Fischer |
| 6 |
% |
| 7 |
% It may be distributed and/or modified under the conditions of the |
| 8 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 9 |
% license or (at your option) any later version. The latest version |
| 10 |
% of this license is in the file |
| 11 |
% |
| 12 |
% https://www.latex-project.org/lppl.txt |
| 13 |
% |
| 14 |
% This file is part of the "tagpdf bundle" (The Work in LPPL) |
| 15 |
% and all files in that bundle must be distributed together. |
| 16 |
% |
| 17 |
% ----------------------------------------------------------------------- |
| 18 |
% |
| 19 |
% The development version of the bundle can be found at |
| 20 |
% |
| 21 |
% https://github.com/latex3/tagpdf |
| 22 |
% |
| 23 |
% for those people who are interested. |
| 24 |
%<*driver> |
| 25 |
\DocumentMetadata{tagging=on} |
| 26 |
\documentclass{l3in2edoc} |
| 27 |
\usepackage{array,booktabs,caption} |
| 28 |
\hypersetup{pdfauthor=Ulrike Fischer, |
| 29 |
pdftitle=tagpdf-space module (tagpdf)} |
| 30 |
\begin{document} |
| 31 |
\DocInput{\jobname.dtx} |
| 32 |
\end{document} |
| 33 |
%</driver> |
| 34 |
% \fi |
| 35 |
% \title{^^A |
| 36 |
% The \pkg{tagpdf-space} module\\ Code related to real space chars ^^A |
| 37 |
% } |
| 38 |
% |
| 39 |
% \author{^^A |
| 40 |
% Ulrike Fischer\thanks |
| 41 |
% {^^A |
| 42 |
% E-mail: |
| 43 |
% \href{mailto:[email protected]} |
| 44 |
% {[email protected]}^^A |
| 45 |
% }^^A |
| 46 |
% } |
| 47 |
% |
| 48 |
% \date{Version 1.0c, released 2026-05-17} |
| 49 |
% \maketitle |
| 50 |
% \begin{documentation} |
| 51 |
% \begin{function}{activate/space (setup-key),interwordspace (deprecated)} |
| 52 |
% This key allows to activate/deactivate the real space chars if the engine supports |
| 53 |
% it. The allowed values are |true|, |on|, |false|, |off|. |
| 54 |
% The old name of the key |interwordspace| is still supported but deprecated. |
| 55 |
% \end{function} |
| 56 |
% \begin{function}{show-spaces (deprecated)} |
| 57 |
% This key is deprecated. Use |debug/show=spaces| instead. |
| 58 |
% This key works only with luatex and shows with small red |
| 59 |
% bars where spaces have been inserted. This is only for debugging and |
| 60 |
% is not completely reliable (and change affect other literals and tagging), so it |
| 61 |
% should be used with care. |
| 62 |
% \end{function} |
| 63 |
% \end{documentation} |
| 64 |
% \begin{implementation} |
| 65 |
% \begin{macrocode} |
| 66 |
%<@@=tag> |
| 67 |
%<*header> |
| 68 |
\ProvidesExplPackage {tagpdf-space-code} {2026-05-17} {1.0c} |
| 69 |
{part of tagpdf - code related to real space chars} |
| 70 |
%</header> |
| 71 |
% \end{macrocode} |
| 72 |
% \section{Code for interword spaces} |
| 73 |
% The code is engine/backend dependent. Basically only pdftex and luatex |
| 74 |
% support real space chars. Most of the code for luatex which uses attributes |
| 75 |
% is in the lua code, here are only the keys. |
| 76 |
% |
| 77 |
% \begin{macro}{activate/spaces (setup-key),interwordspace (deprecated),show-spaces (deprecated)} |
| 78 |
% \begin{macrocode} |
| 79 |
%<*package> |
| 80 |
\bool_new:N\l_@@_showspaces_bool |
| 81 |
\keys_define:nn { @@ / setup } |
| 82 |
{ |
| 83 |
activate/spaces .choice:, |
| 84 |
activate/spaces/true .code:n = |
| 85 |
{ \msg_warning:nne {tag}{sys-no-interwordspace}{\c_sys_engine_str} }, |
| 86 |
activate/spaces/false .code:n= |
| 87 |
{ \msg_warning:nne {tag}{sys-no-interwordspace}{\c_sys_engine_str} }, |
| 88 |
activate/spaces .default:n = true, |
| 89 |
debug/show/spaces .code:n = {\bool_set_true:N \l_@@_showspaces_bool}, |
| 90 |
debug/show/spacesOff .code:n = {\bool_set_false:N \l_@@_showspaces_bool}, |
| 91 |
% \end{macrocode} |
| 92 |
% deprecated versions: |
| 93 |
% \begin{macrocode} |
| 94 |
interwordspace .choices:nn = {true,on}{\keys_set:nn{@@/setup}{activate/spaces={true}}}, |
| 95 |
interwordspace .choices:nn = {false,off}{\keys_set:nn{@@/setup}{activate/spaces={false}}}, |
| 96 |
interwordspace .default:n = {true}, |
| 97 |
show-spaces .choice:, |
| 98 |
show-spaces/true .meta:n = {debug/show=spaces}, |
| 99 |
show-spaces/false .meta:n = {debug/show=spacesOff}, |
| 100 |
show-spaces .default:n = true |
| 101 |
} |
| 102 |
\sys_if_engine_pdftex:T |
| 103 |
{ |
| 104 |
\sys_if_output_pdf:TF |
| 105 |
{ |
| 106 |
\pdfglyphtounicode{space}{0020} |
| 107 |
\AddToHook{shipout/firstpage}[tagpdf/space]{} |
| 108 |
\keys_define:nn { @@ / setup } |
| 109 |
{ |
| 110 |
activate/spaces/true .code:n = { \AddToHook{shipout/firstpage}[tagpdf/space]{\pdfinterwordspaceon} }, |
| 111 |
activate/spaces/false .code:n = { \RemoveFromHook{shipout/firstpage}[tagpdf/space] }, |
| 112 |
activate/spaces .default:n = true, |
| 113 |
} |
| 114 |
} |
| 115 |
{ |
| 116 |
\keys_define:nn { @@ / setup } |
| 117 |
{ |
| 118 |
activate/spaces .choices:nn = { true, false } |
| 119 |
{ \msg_warning:nnn {tag}{sys-no-interwordspace}{dvi} }, |
| 120 |
activate/spaces .default:n = true, |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
\sys_if_engine_luatex:T |
| 127 |
{ |
| 128 |
\keys_define:nn { @@ / setup } |
| 129 |
{ |
| 130 |
activate/spaces .choice:, |
| 131 |
activate/spaces/true .code:n = |
| 132 |
{ |
| 133 |
\bool_gset_true:N \g_@@_active_space_bool |
| 134 |
\lua_now:e{ltx.@@.func.markspaceon()} |
| 135 |
}, |
| 136 |
activate/spaces/false .code:n = |
| 137 |
{ |
| 138 |
\bool_gset_false:N \g_@@_active_space_bool |
| 139 |
\lua_now:e{ltx.@@.func.markspaceoff()} |
| 140 |
}, |
| 141 |
activate/spaces .default:n = true, |
| 142 |
debug/show/spaces .code:n = |
| 143 |
{\lua_now:e{ltx.@@.trace.showspaces=true}}, |
| 144 |
debug/show/spacesOff .code:n = |
| 145 |
{\lua_now:e{ltx.@@.trace.showspaces=nil}}, |
| 146 |
} |
| 147 |
} |
| 148 |
% \end{macrocode} |
| 149 |
% \end{macro} |
| 150 |
% |
| 151 |
% \begin{macro}{\@@_fakespace:} |
| 152 |
% For luatex we need a command for the fake space as equivalent of the pdftex |
| 153 |
% primitive. |
| 154 |
% \begin{macrocode} |
| 155 |
\sys_if_engine_luatex:T |
| 156 |
{ |
| 157 |
\cs_new_protected:Nn \@@_fakespace: |
| 158 |
{ |
| 159 |
\group_begin: |
| 160 |
\lua_now:e{ltx.@@.func.fakespace()} |
| 161 |
\skip_horizontal:n{\c_zero_skip} |
| 162 |
\group_end: |
| 163 |
} |
| 164 |
} |
| 165 |
% \end{macrocode} |
| 166 |
% |
| 167 |
% We need also a command to interrupt the insertion of real space |
| 168 |
% chars in places where we want to insert manually special spaces. |
| 169 |
% In pdftex this can be done with \cs{pdfinterwordspaceoff} |
| 170 |
% and \cs{pdfinterwordspaceon}. These commands insert whatsits |
| 171 |
% and this mean they act globally. In luatex a attribute is |
| 172 |
% used to this effect, for consistency this is also set globally. |
| 173 |
% |
| 174 |
% |
| 175 |
% \begin{macro}{\tag_spacechar_on:,\tag_spacechar_off:} |
| 176 |
% The off command sets the attributes in luatex. |
| 177 |
% \begin{macrocode} |
| 178 |
\cs_new_protected:Npn \tag_spacechar_off: {} |
| 179 |
\cs_new_protected:Npn \tag_spacechar_on: {} |
| 180 |
|
| 181 |
\sys_if_engine_luatex:T |
| 182 |
{ |
| 183 |
\cs_set_protected:Npn \tag_spacechar_off: |
| 184 |
{ |
| 185 |
\lua_now:e |
| 186 |
{ |
| 187 |
tex.setattribute |
| 188 |
( |
| 189 |
"global", |
| 190 |
luatexbase.attributes.g_@@_interwordspaceOff_attr, |
| 191 |
1 |
| 192 |
) |
| 193 |
} |
| 194 |
} |
| 195 |
\cs_set_protected:Npn \tag_spacechar_on: |
| 196 |
{ |
| 197 |
\lua_now:e |
| 198 |
{ |
| 199 |
tex.setattribute |
| 200 |
( |
| 201 |
"global", |
| 202 |
luatexbase.attributes.g_@@_interwordspaceOff_attr, |
| 203 |
-2147483647 |
| 204 |
) |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
\sys_if_engine_pdftex:T |
| 209 |
{ |
| 210 |
\sys_if_output_pdf:T |
| 211 |
{ |
| 212 |
\cs_set_protected:Npn \tag_spacechar_off: |
| 213 |
{ |
| 214 |
\pdfinterwordspaceoff |
| 215 |
} |
| 216 |
\cs_set_protected:Npn \tag_spacechar_on: |
| 217 |
{ |
| 218 |
\pdfinterwordspaceon |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
% \end{macrocode} |
| 223 |
% \end{macro} |
| 224 |
% \begin{macrocode} |
| 225 |
%</package> |
| 226 |
% \end{macrocode} |
| 227 |
% \end{macro} |
| 228 |
% \end{implementation} |
| 229 |
% \PrintIndex |