diff options
Diffstat (limited to 'Master/texmf-dist/source/lualatex/lualatex-math/lualatex-math.dtx')
-rw-r--r-- | Master/texmf-dist/source/lualatex/lualatex-math/lualatex-math.dtx | 421 |
1 files changed, 362 insertions, 59 deletions
diff --git a/Master/texmf-dist/source/lualatex/lualatex-math/lualatex-math.dtx b/Master/texmf-dist/source/lualatex/lualatex-math/lualatex-math.dtx index 12bf9cbd2f8..1e6cf4c7630 100644 --- a/Master/texmf-dist/source/lualatex/lualatex-math/lualatex-math.dtx +++ b/Master/texmf-dist/source/lualatex/lualatex-math/lualatex-math.dtx @@ -31,7 +31,7 @@ %</driver> % \fi % -% \CheckSum{721} +% \CheckSum{886} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -51,6 +51,7 @@ % % % \changes{v0.1}{2011/04/22}{Initial version} +% \changes{v0.3a}{2011/09/13}{Updated for changes in \pkg{l3kernel}} % % \GetFileInfo{lualatex-math.sty} % @@ -68,19 +69,19 @@ % \Hologo{LuaTeX} brings major improvements to all areas of \hologo{TeX} % typesetting and programming. They are made available through new primitives % or the embedded Lua interpreter, and combining them with existing -% \hologo{LaTeX2e} package is not a task the average \hologo{LaTeX} user should -% have to care about. Therefore a multitude of \hologo{LaTeX2e} packages have -% been written to bridge the gap between documents and the new features. The -% \thispackage package focuses on the additional possibilities for mathematical -% typesetting. The most eminent of the new features is the ability to use -% Unicode and OpenType fonts, as provided by \Robertson’s \pkg{unicode-math} -% package. However, there is a smaller group of changes unrelated to Unicode: -% these are to be dealt with in this package. While in principle most -% \hologo{TeX} documents written for traditional engines should work just fine -% with \hologo{LuaTeX}, there is a small number of breaking changes that -% require the attention of package authors. The \thispackage package tries to -% fix some of the issues encountered while porting traditional macro packages -% to \hologo{LuaLaTeX}. +% \hologo{LaTeX2e} packages is not a task the average \hologo{LaTeX} user +% should have to care about. Therefore a multitude of \hologo{LaTeX2e} +% packages have been written to bridge the gap between documents and the new +% features. The \thispackage package focuses on the additional possibilities +% for mathematical typesetting. The most eminent of the new features is the +% ability to use Unicode and OpenType fonts, as provided by \Robertson’s +% \pkg{unicode-math} package. However, there is a smaller group of changes +% unrelated to Unicode: these are to be dealt with in this package. While in +% principle most \hologo{TeX} documents written for traditional engines should +% work just fine with \hologo{LuaTeX}, there is a small number of breaking +% changes that require the attention of package authors. The \thispackage +% package tries to fix some of the issues encountered while porting traditional +% macro packages to \hologo{LuaLaTeX}. % % The decision to write patches for existing macro packages should not be made % lightly: monkey patching done by somebody different from the original package @@ -109,12 +110,12 @@ % \pkg{unicode-math} package; the fixes provided here are valid for both % Unicode and legacy math typesetting. % -% Currently patches for the \hologo{LaTeX2e} kernel and the \pkg{amsmath} and -% \pkg{mathtools} packages are provided. It is not relevant whether you load -% these packages before or after \thispackage. They should work as expected -% (and ideally you shouldn’t notice anything), but if you load other packages -% that by themselves overwrite commands patched by this package, bad things may -% happen, as it is usual with \hologo{LaTeX}. +% Currently patches for the \hologo{LaTeX2e} kernel and the \pkg{amsmath}, +% \pkg{mathtools} and \pkg{icomma} packages are provided. It is not relevant +% whether you load these packages before or after \thispackage. They should +% work as expected (and ideally you shouldn’t notice anything), but if you load +% other packages that by themselves overwrite commands patched by this package, +% bad things may happen, as it is usual with \hologo{LaTeX}. % % One user-visible change is that the new % \DescribeMacros{\mathstyle\luatexmathstyle}\cmd{\mathstyle} primitive @@ -136,8 +137,8 @@ % \begin{macrocode} %<*package> \NeedsTeXFormat{LaTeX2e}[2009/09/24] -\RequirePackage{expl3}[2011/02/17] -\ProvidesExplPackage{lualatex-math}{2011/05/05}{0.1}% +\RequirePackage{expl3}[2011/09/05] +\ProvidesExplPackage{lualatex-math}{2011/09/13}{0.3a}% {Patches for mathematics typesetting with LuaLaTeX} \RequirePackage { etoolbox } [ 2007/10/08 ] \RequirePackage { luatexbase } [ 2010/05/27 ] @@ -163,7 +164,7 @@ \exp_args:Nx \AtEndOfPackage { \lltxmath_restore_catcode:N \$ } -\char_make_math_shift:N \$ +\char_set_catcode_math_toggle:N \$ % \end{macrocode} % % @@ -179,6 +180,22 @@ % \end{macrocode} % \end{l3message} % +% \begin{l3message}{different-meanings} +% Issued when two control sequences have different meanings, but should not. +% \begin{macrocode} +\msg_new:nnnn { lualatex-math } { different-meanings } { + I've~ expected~ the~ control~ sequences \\ + #1~ and~ #3 \\ + to~ have~ the~ same~ meaning,~ but~ their~ meanings~ are~ different. +} { + The~ meaning~ of~ #1~ is: \\ + #2 \\ + The~ meaning~ of~ #3~ is: \\ + #4 +} +% \end{macrocode} +% \end{l3message} +% % \begin{l3message}{macro-expected} % Issued when trying to patch a non-macro. The first argument must be the % detokenized macro name. @@ -233,13 +250,45 @@ % \begin{macro}{\lltxmath_temp:w} % A scratch macro. % \begin{macrocode} -\chk_if_free_cs:N \lltxmath_temp:w +\cs_new_eq:NN \lltxmath_temp:w \prg_do_nothing: +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\luatexUmathcode} +% \begin{macro}{\luatexUmathcodenum} +% \begin{macro}{\luatexUmathchardef} +% We need the extended versions of \cmd{\mathcode} and \cmd{\mathchardef}. +% The command \cmd{\luatexbase@ensure@primitive}\marg{name} makes sure that +% the \hologo{LuaTeX} primitive \cs{\meta{name}} is available under the +% qualified name \cs{luatex\meta{name}}. +% \begin{macrocode} +\luatexbase@ensure@primitive { Umathcode } +\luatexbase@ensure@primitive { Umathcodenum } +\luatexbase@ensure@primitive { Umathchardef } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\lltxmath_assert_eq:NN} +% The macro \cmd{\lltxmath_assert_eq:NN}\meta{first command}\meta{second +% command} tests whether the control sequences \meta{first command} and +% \meta{second command} have the same meaning, and prints an error message if +% they do not. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \lltxmath_assert_eq:NN #1 #2 { + \cs_if_eq:NNF #1 #2 { + \msg_error:nnxxxx { lualatex-math } { different-meanings } + { \token_to_str:N #1 } { \token_to_meaning:N #1 } + { \token_to_str:N #2 } { \token_to_meaning:N #2 } + } +} % \end{macrocode} % \end{macro} % % \begin{macro}{\lltxmath_patch:NNnnn} % \begin{macro}{\lltxmath_patch:cNnnn} -% The macro \cmd{\lltxmath_patch:NNnnn}\meta{command}\meta{factory +% The auxiliary macro \cmd{\lltxmath_patch:NNnnn}\meta{command}\meta{factory % command}\marg{parameter text}\marg{expected replacement text}\marg{new % replacement text} tries to patch \meta{command}. If \meta{command} is % undefined, do nothing. Otherwise it must be a macro with the given @@ -275,9 +324,58 @@ % \end{macro} % \end{macro} % +% \begin{macro}{\lltxmath_set_mathchar:NN} +% The macro \cmd{\lltxmath_set_mathchar:NN}\meta{control +% sequence}\meta{token} defines the \meta{control sequence} as an extended +% mathematical character shorthand whose mathematical code is given by the +% mathematical code of the character \texttt{\textasciigrave}\meta{token}. +% Since there is no \cmd{\Umathcharnumdef} primitive, we have to extract the +% class, family, and slot numbers separately. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \lltxmath_set_mathchar:NN #1 #2 { + \luatexUmathchardef #1 + \lua_now:x { + lualatex.math.print_class_fam_slot( \int_eval:n { `#2 } ) + } + \scan_stop: +} +% \end{macrocode} +% \end{macro} +% % % \subsection{\Hologo{LaTeX2e} kernel} % +% \changes{v0.3}{2011/08/07}{Patched math group allocation to gain access to +% all families} +% In \hologo{LuaTeX}, we have 256 math families at our disposal. Therefore we +% modify the \hologo{LaTeX} allocation macros \cmd{\newfam} and +% \cmd{\new@mathgroup} accordingly. +% +% First we test whether \cmd{\newfam} and \cmd{\new@mathgroup} are equal. +% \begin{macrocode} +\lltxmath_assert_eq:NN \newfam \new@mathgroup +% \end{macrocode} +% +% \begin{macro}{\new@mathgroup} +% It is enough to modify the maximum number of families known to the +% allocation system; the macro \cmd{\alloc@} takes care of the rest. This +% would work even if the \pkg{etex} package weren’t loaded. +% \begin{macrocode} +\lltxmath_patch:NNnnn \new@mathgroup \cs_set_nopar:Npn { } { + \alloc@ 8 \mathgroup \chardef \sixt@@n +} { + \alloc@ 8 \mathgroup \chardef \c_two_hundred_fifty_six +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\newfam} +% We have to reset \cmd{\newfam} to equal \cmd{\new@mathgroup}. +% \begin{macrocode} +\cs_set_eq:NN \newfam \new@mathgroup +% \end{macrocode} +% \end{macro} +% % \Hologo{LuaTeX} enables access to the current mathematical style via the % \cmd{\mathstyle} primitive. For this to work, fraction-like constructs (\eg, % \meta{numerator} \cmd{\over} \meta{denominator}) have to be enclosed in a @@ -333,16 +431,6 @@ % \cmd{\Ustack} primitive. % \end{itemize} % -% \begin{macro}{\luatexUmathcodenum} -% \begin{macro}{\luatexUmathchardef} -% We need the extended versions of \cmd{\mathcode} and \cmd{\mathchardef}. -% \begin{macrocode} -\luatexbase@ensure@primitive { Umathcodenum } -\luatexbase@ensure@primitive { Umathchardef } -% \end{macrocode} -% \end{macro} -% \end{macro} -% % \begin{macro}{\luatexalignmark} % \begin{macro}{\luatexUstartmath} % \begin{macro}{\luatexUstopmath} @@ -384,24 +472,6 @@ % \end{macro} % \end{macro} % -% \begin{macro}{\lltxmath_set_mathchar:NN} -% The macro \cmd{\lltxmath_set_mathchar:NN}\meta{control -% sequence}\meta{token} defines the \meta{control sequence} as an extended -% mathematical character shorthand whose mathematical code is given by the -% mathematical code of the character \texttt{\textasciigrave}\meta{token}. -% Since there is no \cmd{\Umathcharnumdef} primitive, we have to extract the -% class, family, and slot numbers separately. -% \begin{macrocode} -\cs_new_protected_nopar:Npn \lltxmath_set_mathchar:NN #1 #2 { - \luatexUmathchardef #1 - \lua_now:x { - lualatex.math.print_class_fam_slot( \int_eval:n { `#2 } ) - } - \scan_stop: -} -% \end{macrocode} -% \end{macro} -% % \begin{macro}{\lltxmath_char_dim:NN} % The macro \cmd{\lltxmath_char_dim:NN}\meta{primitive}\meta{token} expands % to a \meta{dimen} whose value is the metric of the mathematical character @@ -672,6 +742,30 @@ } } } +% \end{macrocode} +% \end{macro} +% +% +% \subsection{\pkg{icomma}} +% +% \changes{v0.2}{2011/07/03}{Added patch for the \pkg{icomma} package} +% The \pkg{icomma} package uses |\mathchardef| to save the mathematical code of +% the comma character. This breaks for Unicode fonts. The incompatibility was +% noticed by +% \Breitfeld.\footnote{\url{https://groups.google.com/d/topic/de.comp.text.tex/Cputk-AJS5I/discussion}} +% +% \begin{macro}{\mathcomma} +% \pkg{icomma} defines the mathemathical character shorthand \cmd{\icomma} at +% the beginning of the document, therefore we again patch +% \cmd{\@begindocumenthook}. +% \begin{macrocode} +\AtEndOfPackageFile * { icomma } { + \tl_replace_once:Nnn \@begindocumenthook { + \mathchardef \mathcomma \mathcode `\, + } { + \lltxmath_set_mathchar:NN \mathcomma \, + } +} %</package> % \end{macrocode} % \end{macro} @@ -736,7 +830,7 @@ end % % \section{Test files} % -% Finally two small test files—but not a real test suite. +% Finally six small test files—but not a real test suite. % % % \subsection{Common definitions} @@ -748,7 +842,9 @@ end % Only \pkg{xparse} starting with 2008/08/03 has \cmd{\NewDocumentCommand}. % \begin{macrocode} \usepackage{xparse}[2008/08/03] +\usepackage{luacode} \ExplSyntaxOn +\AtBeginDocument { \errorcontextlines = \c_fifteen } % \end{macrocode} % % \begin{l3message}{pass} @@ -908,7 +1004,7 @@ end % \end{macro} % \end{macro} % -% \begin{macro}{\AssertIntEqual} +% \begin{macro}{\AssertDimEqual} % The command \cmd{\AssertDimEqual}\marg{first expression}\marg{second % expression} asserts that the two dimension expressions are equal. % \begin{macrocode} @@ -979,18 +1075,181 @@ end \NewDocumentCommand \AssertCrampedStyle { } { \test_assert_cramped:Nx \int_if_odd_p:n { cramped } } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\l_test_tmpa_box} +% \begin{macro}{\l_test_tmpb_box} +% Scratch registers for box constructions. +% \begin{macrocode} +\box_new:N \l_test_tmpa_box +\box_new:N \l_test_tmpb_box +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{function}{contains_space} +% The function \func{contains_space}|(head, width)| returns |true| if the +% node list starting at |head| or any of its sublists contain a glue or kern +% node of width |width| (or any glue or kern node if |width| is |nil|). +% \begin{macrocode} +\begin{luacode*} +function contains_space(head, width) + for n in node.traverse(head) do + local id = n.id + if id == 10 or id == 11 then + if width then + if (id == 10 and n.spec.width == width) + or (id == 11 and n.kern == width) then + return true + end + else + return true + end + elseif id == 0 or id == 1 then + if contains_space(n.head, width) then + return true + end + end + end + return false +end +\end{luacode*} +% \end{macrocode} +% \end{function} +% +% \begin{macro}{\AssertNoSpace} +% The command \cmd{\AssertNoSpace}\marg{text} asserts that the node list that +% is the result of typesetting \meta{text} contains no glue or kern nodes. +% \begin{macrocode} +\NewDocumentCommand \AssertNoSpace { m } { + \hbox_set:Nn \l_test_tmpa_box { #1 } + \int_if_odd:nTF { + \lua_now:x { + local~ b = tex.getbox(\int_use:N \l_test_tmpa_box) + if~ contains_space(b.head) then~ + tex.sprint("0") + else~ + tex.sprint("1") + end + } + } { + \test_pass:x { + \tl_to_str:n { #1 } ~ + contains~ no~ skip~ or~ kern~ node + } + } { + \test_fail:x { + \tl_to_str:n { #1 } ~ + contains~ a~ skip~ or~ kern~ node + } + } +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\AssertMuSpace} +% The command \cmd{\AssertMuSpace}\marg{text}\marg{muskip} asserts that the +% node list that is the result of typesetting \meta{text} contains at least +% one glue or kern node of with \meta{muskip}. +% \begin{macrocode} +\makeatletter +\NewDocumentCommand \AssertMuSpace { m m } { + \hbox_set:Nn \l_test_tmpa_box { #1 } + \hbox_set:Nn \l_test_tmpb_box { $ \mskip #2 \m@th $ } + \int_if_odd:nTF { + \lua_now:x { + local~ b = tex.getbox(\int_use:N \l_test_tmpa_box) + local~ s = tex.getbox(\int_use:N \l_test_tmpb_box) + if~ contains_space(b.head, s.width) then~ + tex.sprint("1") + else~ + tex.sprint("0") + end + } + } { + \test_pass:x { + \tl_to_str:n { #1 } ~ + contains~ a~ skip~ or~ kern~ node~ of~ width~ + \tl_to_str:n { #2 } + } + } { + \test_fail:x { + \tl_to_str:n { #1 } ~ + contains~ no~ skip~ or~ kern~ node~ of~ width~ + \tl_to_str:n { #2 } + } + } +} +\makeatother \ExplSyntaxOff %</test> % \end{macrocode} % \end{macro} % % -% \subsection{\Hologo{LaTeX2e} kernel} +% \subsection{\Hologo{LaTeX2e} kernel, allocation of math families} +% +% \changes{v0.3}{2011/08/07}{Added test file for modified family allocation +% scheme} +% The \hologo{LaTeX2e} kernel itself allocates four families (also known as +% \enquote{math groups} in \hologo{LaTeX} parlance). Therefore we should still +% be able to allocate 252 families. We do this alternately with \cmd{\newfam}, +% \cmd{\new@mathgroup} and \cmd{\DeclareSymbolFont}. +% \begin{macrocode} +%<*test-kernel-alloc> +\usepackage{lualatex-math} +\makeatletter +\ExplSyntaxOn +\prg_stepwise_inline:nnnn { \c_four } { \c_one } { + \c_two_hundred_fifty_five - \c_one +} { + \prg_case_int:nnn { \int_mod:nn { #1 } { \c_three } } { + { \c_zero } { + \chk_if_free_cs:N \g_test_family_int + \newfam \g_test_family_int + \AssertIntEqual { \g_test_family_int } { #1 } + \cs_undefine:N \g_test_family_int + } + { \c_one } { + \chk_if_free_cs:N \g_test_mathgroup_int + \new@mathgroup \g_test_mathgroup_int + \AssertIntEqual { \g_test_mathgroup_int } { #1 } + \cs_undefine:N \g_test_mathgroup_int + } + { \c_two } { + \DeclareSymbolFont { Test #1 } { OT1 } { cmr } { m } { n } + \exp_args:Nc \AssertIntEqual { sym Test #1 } { #1 } + } + } { + \test_fail:x { This~ cannot~ happen } + } +} +\DeclareSymbolFont { Test 255 } { OT1 } { cmr } { bx } { it } +\DeclareSymbolFontAlphabet { \TestAlphabet } { Test 255 } +\exp_args:Nc \AssertIntEqual { sym Test 255 } + { \c_two_hundred_fifty_five } +\ExplSyntaxOff +\makeatother +\begin{document} +\[ +\TestAlphabet{ + abc + \AssertIntEqual{\fam}{255} + \AssertIntEqual{\mathgroup}{255} +} +\] +\end{document} +%</test-kernel-alloc> +% \end{macrocode} +% +% +% \subsection{\Hologo{LaTeX2e} kernel, \cs{mathstyle} primitive} % % Here we only check whether different fractions and other style-changing % commands result in the correct mathematical style. % \begin{macrocode} -%<*test-kernel> +%<*test-kernel-style> \usepackage{lualatex-math} \begin{document} \begin{displaymath} @@ -1030,7 +1289,7 @@ end \frac{\AssertMathStyle{7}}{\AssertMathStyle{7}} \end{math} \end{document} -%</test-kernel> +%</test-kernel-style> % \end{macrocode} % % @@ -1183,7 +1442,7 @@ end % % This test file loads both \pkg{amsmath} and \pkg{unicode-math}. The latter % package contains fixes that somewhat overlap with ours. We have to take care -% in all packages that no attempt is made to patch a sinlge macro twice. +% in all packages that no attempt is made to patch a single macro twice. % Therefore we treat warnings (that occur when trying to patch a macro with an % unknown meaning) as errors here. % @@ -1208,6 +1467,50 @@ end %</test-unicode> % \end{macrocode} % +% +% \subsection{\pkg{icomma} without \pkg{unicode-math}} +% +% \changes{v0.2}{2011/07/03}{Added test file for \pkg{icomma} without +% \pkg{unicode-math}} +% This test file loads only \pkg{icomma} to test whether our patch works for +% Computer Modern. +% +% \begin{macrocode} +%<*test-icomma> +\usepackage{lualatex-math} +\usepackage{icomma} +\begin{document} +$1,234 \; (x, y)$ +\AssertNoSpace{$1,234$} +\AssertMuSpace{$(x, y)$}{\thinmuskip} +\AssertIntEqual{\mathcomma}{"1C0003B} +\end{document} +%</test-icomma> +% \end{macrocode} +% +% +% \subsection{\pkg{icomma} with \pkg{unicode-math}} +% +% \changes{v0.2}{2011/07/03}{Added test file for \pkg{icomma} with +% \pkg{unicode-math}} +% This test file loads both \pkg{icomma} and \pkg{unicode-math} to test whether +% they interact well. +% +% \begin{macrocode} +%<*test-icomma-unicode> +\usepackage{unicode-math}[2011/05/05] +\setmathfont{XITS Math} +\usepackage{lualatex-math} +\usepackage{icomma} +\begin{document} +$1,234 \; (x, y)$ +\AssertNoSpace{$1,234$} +\AssertMuSpace{$(x, y)$}{\thinmuskip} +\AssertIntEqual{\mathcomma}{"0C0002C} +\end{document} +%</test-icomma-unicode> +% \end{macrocode} +% % \Finale \endinput |