diff options
Diffstat (limited to 'macros')
39 files changed, 4031 insertions, 536 deletions
diff --git a/macros/latex/contrib/ut-thesis/README b/macros/latex/contrib/ut-thesis/README index 880fe06c31..785d74c606 100644 --- a/macros/latex/contrib/ut-thesis/README +++ b/macros/latex/contrib/ut-thesis/README @@ -5,8 +5,8 @@ as of Fall 2020: [https://www.sgs.utoronto.ca/academic-progress/program-completion/formatting] Copyright (c) 1998-2013 Francois Pitt <fpitt@cs.utoronto.ca>, - 2020-2021 Jesse Knight <jesse.knight@mail.utoronto.ca> -last updated at 13:00 (EST) on Thu 26 Aug 2021 + 2020-2023 Jesse Knight <jesse.knight@mail.utoronto.ca> +last updated at 13:00 (EST) on Wed 08 Feb 2023 This work may be distributed and/or modified under the conditions of the LaTeX Project Public Licence, either version 1.3c of this licence diff --git a/macros/latex/contrib/ut-thesis/ut-thesis.dtx b/macros/latex/contrib/ut-thesis/ut-thesis.dtx index fa8b3a4c31..873f0bd2c5 100644 --- a/macros/latex/contrib/ut-thesis/ut-thesis.dtx +++ b/macros/latex/contrib/ut-thesis/ut-thesis.dtx @@ -5,7 +5,7 @@ %<class>\NeedsTeXFormat{LaTeX2e}[1999/12/01] %<class>\ProvidesClass{ut-thesis} %<*class> -[2022/06/21 v3.1.6 University of Toronto thesis class] +[2023/02/08 v3.1.7 University of Toronto thesis class] %</class> % %<*driver> @@ -16,7 +16,7 @@ \usepackage[margin=3cm,inner=5cm]{geometry} \usepackage{xcolor} \definecolor{code}{HTML}{990033} -\definecolor{link}{HTML}{000066} +\definecolor{link}{HTML}{006699} \let\ottfamily\ttfamily \renewcommand{\ttfamily}{\color{code}\ottfamily} \renewcommand{\MacroFont}{\ttfamily\color{code}} @@ -32,7 +32,7 @@ % % \GetFileInfo{ut-thesis.dtx} % -% \title{The \texttt{ut-thesis} class +% \title{The \textit{ut-thesis} class % \thanks{\fileversion~[\filedate] CTAN repository: % \href{https://ctan.org/pkg/ut-thesis} % {\texttt{https://ctan.org/pkg/ut-thesis}}}} @@ -47,7 +47,7 @@ % \maketitle % % \begin{abstract}\noindent -% The |ut-thesis| document class implements the formatting requirements of +% The \textit{ut-thesis} document class implements the formatting requirements of % the University of Toronto School of Graduate Studies (SGS), % as of Fall 2020. % \end{abstract} @@ -57,16 +57,19 @@ % % \section{Installation}\label{inst} % -% To use the |ut-thesis| class, -% you must first make the file |ut-thesis.cls| visible to your current \LaTeX\ distribution. -% There are two ways to do this: +% There are two main options to start using the class: % \begin{itemize} -% \item \textbf{local file}: Place the file |ut-thesis.cls| in your project directory. -% This works if you don't have write access -% in the \LaTeX\ distribution, such as if you use Overleaf. -% \item \textbf{installing}: Installation steps will depend on your \LaTeX\ distribution. -% Some helpful instructions can be found +% \item \textbf{installing}: The \textit{ut-thesis} class is available +% under the major \LaTeX\ distributions (Linux: TeX Live, macOS: MacTeX, Windows: MiKTeX). +% Installation steps will depend on the distribution; some helpful information is % \href{https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages}{here}. +% Within TeX Live, \textit{ut-thesis} is part of the +% \href{https://packages.ubuntu.com/kinetic/all/texlive-publishers/filelist} +% {publishers} bundle, so it should be available on Overleaf. +% \item \textbf{local file}: Place the file |ut-thesis.cls| in your project directory. +% The class will only be available in this directory. +% This works if you don't have write access in the \LaTeX\ distribution, +% or if you want to use an updated version of the class. % \end{itemize} % % \section{Usage}\label{use} @@ -76,6 +79,8 @@ % % The default options produce a final copy, ready for submission to % the University of Toronto School of Graduate Studies (SGS). +% Some examples are available on +% \href{https://github.com/jessexknight/ut-thesis/tree/master/test}{GitHub}. % % \subsection{Options}\label{use:opt} % diff --git a/macros/latex/contrib/ut-thesis/ut-thesis.pdf b/macros/latex/contrib/ut-thesis/ut-thesis.pdf Binary files differindex 88b20d0dfb..8f055d54d0 100644 --- a/macros/latex/contrib/ut-thesis/ut-thesis.pdf +++ b/macros/latex/contrib/ut-thesis/ut-thesis.pdf diff --git a/macros/luatex/latex/lualinalg/2dvec.jpg b/macros/luatex/latex/lualinalg/2dvec.jpg Binary files differnew file mode 100644 index 0000000000..7b857ab6d0 --- /dev/null +++ b/macros/luatex/latex/lualinalg/2dvec.jpg diff --git a/macros/luatex/latex/lualinalg/3dvec.jpg b/macros/luatex/latex/lualinalg/3dvec.jpg Binary files differnew file mode 100644 index 0000000000..1f84c4044f --- /dev/null +++ b/macros/luatex/latex/lualinalg/3dvec.jpg diff --git a/macros/luatex/latex/lualinalg/README.txt b/macros/luatex/latex/lualinalg/README.txt new file mode 100644 index 0000000000..fc33bfedec --- /dev/null +++ b/macros/luatex/latex/lualinalg/README.txt @@ -0,0 +1,24 @@ +# Introduction +The lualinalg package is developed to perform operations on vectors and matrices defined over the field of real or complex numbers inside LaTeX documents. +It provides flexible ways for defining and displaying vectors and matrices. +No particular environment of LaTeX is required to use commands in the package. +The package is written in Lua, and tex file is to be compiled with the LuaLaTeX engine. +The time required for calculations is not an issue while compiling with LuaLaTeX. +There is no need to install Lua on the user's system as TeX distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. +It may also save users' efforts to copy vectors and matrices from other software (which may not be in latex-compatible format) and to use them in a tex file. +The vectors and matrices of reasonable size can be handled with ease. +The package can be modified or extended by writing custom Lua programs. + +# License +The \verb|lualinalg| package is released under the LaTeX Project Public License v1.3c or later. +The complete license text is available at \url{http://www.latex-project.org/lppl.txt}. +It is developed in Lua. Lua is available as a certified open-source software. +Its license is simple and liberal, which is compatible with GPL. +The package makes use of \verb|complex.lua| file which is available on \url{https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua}. +It is available under the same licensing as that of Lua. +The package also loads the luamaths package, which is available under the LaTeX Project Public License v1.3c or later. +This package is loaded to use the standard mathematical functions and for computations on real numbers while performing operations on vectors and matrices. + +#Installation and Inclusion +The installation of lualinalg package is similar to plain latex package, where the .sty file is in LaTeX directory of texmf tree. +The package can be included with \usepackage{lualinalg} command in the preamble of the LaTeX document.
\ No newline at end of file diff --git a/macros/luatex/latex/lualinalg/luacomplex.lua b/macros/luatex/latex/lualinalg/luacomplex.lua new file mode 100644 index 0000000000..b817ce66b6 --- /dev/null +++ b/macros/luatex/latex/lualinalg/luacomplex.lua @@ -0,0 +1,298 @@ + +--Version=1.0, Date=31-Jan-2023 +-- provides module for complex numbers + +--Contains a modified version of the file complex.lua. It is availalbe on the link https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua. This is licensed under the same terms as Lua itself. This license allows to freely copy, modify and distribute the file for any purpose and without any restrictions. + +--Licensed under the same terms as Lua itself. This license allows to freely copy, modify and distribute the file for any purpose and without any restrictions. + + + +complex = {} + +local complex_meta = {} + +local function parse_scalar(s, pos0) + local x, n, pos = s:match('^([+-]?[%d%.]+)(.?)()', pos0) + if not x then return end + if n == 'e' or n == 'E' then + local x2, n2, pos2 = s:match('^([+-]?%d+)(.?)()', pos) + if not x2 then error 'number format error' end + x = tonumber(x..n..x2) + if not x then error 'number format error' end + return x, n2, pos2 + else + x = tonumber(x) + if not x then error 'number format error' end + return x, n, pos + end +end +local function parse_component(s, pos0) + local x, n, pos = parse_scalar(s, pos0) + if not x then + local x2, n2, pos2 = s:match('^([+-]?)(i)()$', pos0) + if not x2 then error 'number format error' end + return (x2=='-' and -1 or 1), n2, pos2 + end + if n == '/' then + local x2, n2, pos2 = parse_scalar(s, pos) + x = x / x2 + return x, n2, pos2 + end + return x, n, pos +end +local function parse_complex(s) + local x, n, pos = parse_component(s, 1) + if n == '+' or n == '-' then + local x2, n2, pos2 = parse_component(s, pos) + if n2 ~= 'i' or pos2 ~= #s+1 then error 'number format error' end + if n == '-' then x2 = - x2 end + return x, x2 + elseif n == '' then + return x, 0 + elseif n == 'i' then + if pos ~= #s+1 then error 'number format error' end + return 0, x + else + error 'number format error' + end +end + +function complex.to( num ) + -- check for table type + if type( num ) == "table" then + -- check for a complex number + if getmetatable( num ) == complex_meta then + return num + end + local real,imag = tonumber( num[1] ),tonumber( num[2] ) + if real and imag then + return setmetatable( { real,imag }, complex_meta ) + end + return + end + local isnum = tonumber( num ) + if isnum then + return setmetatable( { isnum,0 }, complex_meta ) + end + if type( num ) == "string" then + local real, imag = parse_complex(num) + return setmetatable( { real, imag }, complex_meta ) + end +end + +setmetatable( complex, { __call = function( _,num ) return complex.to( num ) end } ) + + +function complex.new( ... ) + return setmetatable( { ... }, complex_meta ) +end + + +function complex.type( arg ) + if getmetatable( arg ) == complex_meta then + return "complex" + end +end + + +function complex.convpolar( radius, phi ) + return setmetatable( { radius * math.cos( phi ), radius * math.sin( phi ) }, complex_meta ) +end + +function complex.convpolardeg( radius, phi ) + phi = phi/180 * math.pi + return setmetatable( { radius * math.cos( phi ), radius * math.sin( phi ) }, complex_meta ) +end + +function complex.tostring( cx,formatstr ) + local real,imag = cx[1],cx[2] + if formatstr then + if imag == 0 then + return string.format( formatstr, real ) + elseif real == 0 then + return string.format( formatstr, imag ).."i" + elseif imag > 0 then + return string.format( formatstr, real ).."+"..string.format( formatstr, imag ).."i" + end + return string.format( formatstr, real )..string.format( formatstr, imag ).."i" + end + if imag == 0 then + return real + elseif real == 0 then + return ((imag==1 and "") or (imag==-1 and "-") or imag).."i" + elseif imag > 0 then + return real.."+"..(imag==1 and "" or imag).."i" + end + return real..(imag==-1 and "-" or imag).."i" +end + +function complex.print( ... ) + print( complex.tostring( ... ) ) +end + +function complex.polar( cx ) + return math.sqrt( cx[1]^2 + cx[2]^2 ), math.atan2( cx[2], cx[1] ) +end + +function complex.polardeg( cx ) + return math.sqrt( cx[1]^2 + cx[2]^2 ), math.atan2( cx[2], cx[1] ) / math.pi * 180 +end + +function complex.norm2( cx ) + return cx[1]^2 + cx[2]^2 +end + +function complex.abs( cx ) + return math.sqrt( cx[1]^2 + cx[2]^2 ) +end + +function complex.get( cx ) + return cx[1],cx[2] +end + + +function complex.set( cx,real,imag ) + cx[1],cx[2] = real,imag +end + +function complex.is( cx,real,imag ) + if cx[1] == real and cx[2] == imag then + return true + end + return false +end + + +function complex.copy( cx ) + return setmetatable( { cx[1],cx[2] }, complex_meta ) +end + + +function complex.add( cx1,cx2 ) + return setmetatable( { cx1[1]+cx2[1], cx1[2]+cx2[2] }, complex_meta ) +end + + +function complex.sub( cx1,cx2 ) + return setmetatable( { cx1[1]-cx2[1], cx1[2]-cx2[2] }, complex_meta ) +end + +function complex.mul( cx1,cx2 ) + return setmetatable( { cx1[1]*cx2[1] - cx1[2]*cx2[2],cx1[1]*cx2[2] + cx1[2]*cx2[1] }, complex_meta ) +end + + +function complex.mulnum( cx,num ) + return setmetatable( { cx[1]*num,cx[2]*num }, complex_meta ) +end + +function complex.div( cx1,cx2 ) + local val = cx2[1]^2 + cx2[2]^2 + return setmetatable( { (cx1[1]*cx2[1]+cx1[2]*cx2[2])/val,(cx1[2]*cx2[1]-cx1[1]*cx2[2])/val }, complex_meta ) +end + +function complex.divnum( cx,num ) + return setmetatable( { cx[1]/num,cx[2]/num }, complex_meta ) +end + + +function complex.pow( cx,num ) + if math.floor( num ) == num then + if num < 0 then + local val = cx[1]^2 + cx[2]^2 + cx = { cx[1]/val,-cx[2]/val } + num = -num + end + local real,imag = cx[1],cx[2] + for i = 2,num do + real,imag = real*cx[1] - imag*cx[2],real*cx[2] + imag*cx[1] + end + return setmetatable( { real,imag }, complex_meta ) + end + local length,phi = math.sqrt( cx[1]^2 + cx[2]^2 )^num, math.atan2( cx[2], cx[1] )*num + return setmetatable( { length * math.cos( phi ), length * math.sin( phi ) }, complex_meta ) +end + +function complex.sqrt( cx ) + local len = math.sqrt( cx[1]^2+cx[2]^2 ) + local sign = (cx[2]<0 and -1) or 1 + return setmetatable( { math.sqrt((cx[1]+len)/2), sign*math.sqrt((len-cx[1])/2) }, complex_meta ) +end + + +function complex.ln( cx ) + return setmetatable( { math.log(math.sqrt( cx[1]^2 + cx[2]^2 )), + math.atan2( cx[2], cx[1] ) }, complex_meta ) +end + +function complex.exp( cx ) + local expreal = math.exp(cx[1]) + return setmetatable( { expreal*math.cos(cx[2]), expreal*math.sin(cx[2]) }, complex_meta ) +end + + +function complex.conjugate( cx ) + return setmetatable( { cx[1], -cx[2] }, complex_meta ) +end + +function complex.round( cx,idp ) + local mult = 10^( idp or 0 ) + return setmetatable( { math.floor( cx[1] * mult + 0.5 ) / mult, + math.floor( cx[2] * mult + 0.5 ) / mult }, complex_meta ) +end + + +complex.zero = complex.new(0, 0) +complex.one = complex.new(1, 0) + + + +complex_meta.__add = function( cx1,cx2 ) + local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 ) + return complex.add( cx1,cx2 ) +end +complex_meta.__sub = function( cx1,cx2 ) + local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 ) + return complex.sub( cx1,cx2 ) +end +complex_meta.__mul = function( cx1,cx2 ) + local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 ) + return complex.mul( cx1,cx2 ) +end +complex_meta.__div = function( cx1,cx2 ) + local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 ) + return complex.div( cx1,cx2 ) +end +complex_meta.__pow = function( cx,num ) + if num == "*" then + return complex.conjugate( cx ) + end + return complex.pow( cx,num ) +end +complex_meta.__unm = function( cx ) + return setmetatable( { -cx[1], -cx[2] }, complex_meta ) +end +complex_meta.__eq = function( cx1,cx2 ) + if cx1[1] == cx2[1] and cx1[2] == cx2[2] then + return true + end + return false +end +complex_meta.__tostring = function( cx ) + return tostring( complex.tostring( cx ) ) +end +complex_meta.__concat = function( cx,cx2 ) + return tostring(cx)..tostring(cx2) +end +-- cx( cx, formatstr ) +complex_meta.__call = function( ... ) + print( complex.tostring( ... ) ) +end +complex_meta.__index = {} +for k,v in pairs( complex ) do + complex_meta.__index[k] = v +end + +return complex + diff --git a/macros/luatex/latex/lualinalg/lualinalg.pdf b/macros/luatex/latex/lualinalg/lualinalg.pdf Binary files differnew file mode 100644 index 0000000000..bdc2769722 --- /dev/null +++ b/macros/luatex/latex/lualinalg/lualinalg.pdf diff --git a/macros/luatex/latex/lualinalg/lualinalg.sty b/macros/luatex/latex/lualinalg/lualinalg.sty new file mode 100644 index 0000000000..53fe7fd688 --- /dev/null +++ b/macros/luatex/latex/lualinalg/lualinalg.sty @@ -0,0 +1,1685 @@ + +% The lualinalg package +% Authors: Chetan Shirore and Ajit Kumar +% version 1.0 +% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt. + + +\ProvidesPackage{lualinalg}[1.0] +\RequirePackage{xkeyval} +\RequirePackage{amsmath} +\RequirePackage{luamaths} +\RequirePackage{luacode} +\begin{luacode*} +local complex = require "luacomplex" + +-- matrices part +matrices = {} + +matrix = {} --module + +local matrix_meta = {} + +function matrix.new(matrix, rows, columns) + if type(rows) == "table" then + for i = 1, #rows do + if #rows[1] ~= #rows[i] then + error("Check input matrix.") + end + end + return setmetatable(rows, matrix_meta) + end + local mtx = {} + if columns == "I" then + for i = 1, rows do + mtx[i] = {} + for j = 1, rows do + if i == j then + mtx[i][j] = 1 + else + mtx[i][j] = 0 + end + end + end + return setmetatable(mtx, matrix_meta) + end +end + +setmetatable( + matrix, + {__call = function(...) + return matrix.new(...) + end} +) + +function matrix.add(m1, m2) + local mtx = {} + for i = 1, #m1 do + local m3i = {} + mtx[i] = m3i + for j = 1, #m1[1] do + m3i[j] = m1[i][j] + m2[i][j] + end + end + return setmetatable(mtx, matrix_meta) +end +function matrix.sub(m1, m2) + local mtx = {} + for i = 1, #m1 do + local m3i = {} + mtx[i] = m3i + for j = 1, #m1[1] do + m3i[j] = m1[i][j] - m2[i][j] + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.mulnum(m1, num) + local mtx = {} + -- multiply elements with number + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] * num + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.mul(m1, m2) + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m2[1] do + local num = m1[i][1] * m2[1][j] + for n = 2, #m1[1] do + num = num + m1[i][n] * m2[n][j] + end + mtx[i][j] = num + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.swapRows(m1, p, q) + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + for j = 1, #m1[1] do + rowHold = m1[p][j] + mtx[p][j] = m1[q][j] + mtx[q][j] = rowHold + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.swapCols(m1, p, q) + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + for j = 1, #m1 do + rowHold = m1[j][p] + mtx[j][p] = m1[j][q] + mtx[j][q] = rowHold + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.mulRow(m1, p, k) + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + for j = 1, #m1[1] do + mtx[p][j] = k * m1[p][j] + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.mulAddRow(m1, k, p, q) + if p == q then + error("Can't operate on same row.") + end + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + for j = 1, #m1[1] do + mtx[q][j] = k * (mtx[p][j]) + mtx[q][j] + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.mulCol(m1, p, k) + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + for j = 1, #m1 do + mtx[j][p] = k * m1[j][p] + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.mulAddCol(m1, k, p, q) + if p == q then + error("Can't operate on same column.") + end + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + for j = 1, #m1 do + mtx[j][q] = k * mtx[j][p] + mtx[j][q] + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.transpose(m1) + local mtx = {} + for i = 1, #m1[1] do + mtx[i] = {} + for j = 1, #m1 do + mtx[i][j] = m1[j][i] + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.subm(m1, i1, j1, i2, j2) + local mtx = {} + for i = i1, i2 do + local _i = i - i1 + 1 + mtx[_i] = {} + for j = j1, j2 do + local _j = j - j1 + 1 + mtx[_i][_j] = m1[i][j] + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.concath(m1, m2) + if #m1 ~= #m2 then + error("No. of rows must be equal.") + end + local mtx = {} + local offset = #m1[1] + for i = 1, #m1 do + mtx[i] = {} + for j = 1, offset do + mtx[i][j] = m1[i][j] + end + for j = 1, #m2[1] do + mtx[i][j + offset] = m2[i][j] + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.concatv(m1, m2) + if #m1[1] ~= #m2[1] then + error("No. of columns must be equal.") + end + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + local offset = #mtx + for i = 1, #m2 do + local _i = i + offset + mtx[_i] = {} + for j = 1, #m2[1] do + mtx[_i][j] = m2[i][j] + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.rows(mtx) + return #mtx +end + +function matrix.columns(mtx) + return #mtx[1] +end + +setmetatable( + matrix, + {__call = function(...) + return matrix.new(...) + end} +) + +function matrix.getelement(mtx, i, j) + if mtx[i] and mtx[i][j] then + return mtx[i][j] + end +end + +function matrix.setelement(mtx, i, j, value) + if matrix.getelement(mtx, i, j) then + mtx[i][j] = value + return value + end +end + +function matrix.invert(m1) + if #m1 ~= #m1[1] then + error("matrix not square") + end + if matrix.det(m1) == 0 then + error("matrix not invertible") + end + local mtx = {} + local idnt = matrix(#m1, "I") + mtx = matrix.subm(matrix.rref(matrix.concath(m1, idnt)), 1, #m1 + 1, #m1, #m1 + #m1) + return mtx +end + +function matrix.trace(m1) + if #m1 ~= #m1[1] then + error("matrix not square") + end + local sum = 0 + + for i = 1, #m1 do + for j = 1, #m1[1] do + if i == j then + sum = sum + m1[i][j] + end + end + end + + return sum +end + +function matrix.normF(mtx) + local result = 0 + for i = 1, #mtx do + for j = 1, #mtx[1] do + local e = mtx[i][j] + result = result + complex.abs(complex(e)) ^ 2 + end + end + return complex.sqrt(complex(result)) +end + +function matrix.normmax(mtx) + local result = 0 + for i = 1, #mtx do + for j = 1, #mtx[1] do + local e = complex.abs(complex(mtx[i][j])) + if e > result then + result = e + end + end + end + return result +end + +function matrix.norminfty(mtx) + local e = 0 + local result = 0 + for i = 1, #mtx do + local e = 0 + for j = 1, #mtx[1] do + e = e + complex.abs(complex(mtx[i][j])) + end + if e > result then + result = e + end + end + return result +end + +function matrix.norm1(mtx) + local e = 0 + local result = 0 + for i = 1, #mtx[1] do + local e = 0 + for j = 1, #mtx do + e = e + complex.abs(complex(mtx[j][i])) + end + if e > result then + result = e + end + end + return result +end + +function matrix.conjugate(m1) + local mtx = matrix.copy(m1) + for i = 1, #mtx do + for j = 1, #mtx[1] do + mtx[i][j] = complex.conjugate(complex(mtx[i][j])) + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.conjugateT(m1) + local mtx = {} + for i = 1, #m1[1] do + mtx[i] = {} + for j = 1, #m1 do + mtx[i][j] = complex.conjugate(complex(m1[j][i])) + end + end + return setmetatable(mtx, matrix_meta) +end + +function copy(x) + return type(x) == "table" and x.copy(x) or x +end + +function matrix.pow(m1, num) + assert(num == math.floor(num), "exponent not an integer") + if num == 0 then + return matrix:new(#m1, "I") + end + if num < 0 then + local rank + m1, rank = matrix.invert(m1) + if not m1 then + return m1, rank + end -- singular + num = -num + end + local mtx = matrix.copy(m1) + for i = 2, num do + mtx = matrix.mul(mtx, m1) + end + return mtx +end + +function matrix.createrandom(nrow, ncol, start, stop) + mtx = {} + for i = 1, nrow do + mtx[i] = {} + for j = 1, ncol do + mtx[i][j] = math.random(start, stop) + mtx[i][j] = mtx[i][j] + math.min(math.random(), math.abs(mtx[i][j] - start), math.abs(stop - mtx[i][j])) + end + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.process(m1) + --m1=load("return "..m1)() + return matrix.mulnum(m1, 1.0) +end + +function matrix.det(m1) + assert(#m1 == #m1[1], "matrix not square") + + local size = #m1 + + if size == 1 then + return m1[1][1] + end + + if size == 2 then + return m1[1][1] * m1[2][2] - m1[2][1] * m1[1][2] + end + + if size == 3 then + return (m1[1][1] * m1[2][2] * m1[3][3] + m1[1][2] * m1[2][3] * m1[3][1] + m1[1][3] * m1[2][1] * m1[3][2] - + m1[1][3] * m1[2][2] * m1[3][1] - + m1[1][1] * m1[2][3] * m1[3][2] - + m1[1][2] * m1[2][1] * m1[3][3]) + end + + local e = m1[1][1] + local zero = type(e) == "table" and e.zero or 0 + local norm2 = type(e) == "table" and e.norm2 or number_norm2 + + local mtx = matrix.copy(m1) + local det = 1 + + for j = 1, #mtx[1] do + local rows = #mtx + local subdet, xrow + for i = 1, rows do + local e = mtx[i][j] + if not subdet then + if e ~= zero then + subdet, xrow = e, i + end + elseif e ~= zero and math.abs(norm2(e) - 1) < math.abs(norm2(subdet) - 1) then + subdet, xrow = e, i + end + end + if subdet then + if xrow ~= rows then + mtx[rows], mtx[xrow] = mtx[xrow], mtx[rows] + det = -det + end + + for i = 1, rows - 1 do + if mtx[i][j] ~= zero then + local factor = mtx[i][j] / subdet + for n = j + 1, #mtx[1] do + mtx[i][n] = mtx[i][n] - factor * mtx[rows][n] + end + end + end + if math.fmod(rows, 2) == 0 then + det = -det + end + det = det * subdet + table.remove(mtx) + else + return det * 0 + end + end + + return det +end + +function matrix.copy(m1) + local mtx = {} + for i = 1, #m1 do + mtx[i] = {} + for j = 1, #m1[1] do + mtx[i][j] = m1[i][j] + end + end + return setmetatable(mtx, matrix_meta) +end + +norm2 = type(e) == "table" and e.norm2 or number_norm2 + +function number_norm2(x) + return x * x +end + +function matrix.op(exp) + return load("return " .. exp, exp, "t", matrices)() +end + +function matrix.rref(mtx) + local mtx = matrix.copy(mtx) + step = 1 + lead = 1 + rowCount = #mtx + columnCount = #mtx[1] + for r = 1, rowCount do + if lead > columnCount then + return mtx + end + i = r + while (mtx[i][lead] == 0) do + i = i + 1 + if (i - 1 == rowCount) then + i = r + if (columnCount == lead) then + return mtx + end + lead = lead + 1 + end + end + + if i ~= r then + mtx = matrix.swapRows(mtx, i, r) + end + + local m = mtx[r][lead] + if (mtx[r][lead] ~= 0) then + for u = 1, columnCount do + mtx[r][u] = mtx[r][u] / m + end + end + for i = 1, rowCount do + local m = mtx[i][lead] + if (i ~= r) then + for v = 1, columnCount do + mtx[i][v] = mtx[i][v] - m * mtx[r][v] + end + end + end + lead = lead + 1 + end + return mtx +end + +function matrix.rref0E(mtx, fom, dignum) + local strng = "" + truncate = truncate or 6 + local mtx = matrix.copy(mtx) + step = 1 + lead = 1 + stepCnt = 0 + rowCount = #mtx + columnCount = #mtx[1] + for r = 1, rowCount do + if lead > columnCount then + return mtx + end + i = r + while (mtx[i][lead] == 0) do + i = i + 1 + if (i - 1 == rowCount) then + i = r + if (columnCount == lead) then + if stepCnt == 0 then + stepCnt = stepCnt + 1 + strng = strng .. "Step " .. tostring(stepCnt) ".$$" .. tostring(matrix.show(mtx, fom, dignum)) + return strng + end + return strng + end + lead = lead + 1 + end + end + + if i ~= r then + mtx = matrix.swapRows(mtx, i, r) + stepCnt = stepCnt + 1 + strng = + strng .. + "Step " .. + tostring(stepCnt) .. + ": Interchange rows " .. + tostring(i) .. + " and " .. tostring(r) .. ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" + end + + local m = mtx[r][lead] + if (mtx[r][lead] ~= 0) then + for u = 1, columnCount do + mtx[r][u] = mtx[r][u] / m + end + if m ~= 1.0 then + if m ~= complex("1.0") then + stepCnt = stepCnt + 1 + strng = + strng .. + "Step " .. + tostring(stepCnt) .. + ": Divide row " .. + tostring(r) .. + " by " .. + tostring(complex.round(complex(m), dignum)) .. + ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" + end + end + end + for i = 1, rowCount do + local m = mtx[i][lead] + if (i ~= r) then + for v = 1, columnCount do + mtx[i][v] = mtx[i][v] - m * mtx[r][v] + end + if m ~= 0 then + if m ~= complex("0.0") then + stepCnt = stepCnt + 1 + strng = + strng .. + "Step " .. + tostring(stepCnt) .. + ": Multiply row " .. + tostring(r) .. + " by " .. + tostring(complex.round(complex(m), dignum)) .. + " and subtract it from row " .. + tostring(i) .. + ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" + end + end + end + end + lead = lead + 1 + end + return strng +end + +function matrix.GaussJordan(mtx, augmt) + local mtx = matrix.copy(mtx) + local augmt = matrix.copy(augmt) + step = 1 + lead = 1 + rowCount = #mtx + columnCount = #mtx[1] + for r = 1, rowCount do + if lead > columnCount then + return matrix.concath(mtx, augmt) + end + i = r + while (mtx[i][lead] == 0) do + i = i + 1 + if (i - 1 == rowCount) then + i = r + if (columnCount == lead) then + return matrix.concath(mtx, augmt) + end + lead = lead + 1 + end + end + + if i ~= r then + mtx = matrix.swapRows(mtx, i, r) + augmt = matrix.swapRows(augmt, i, r) + end + + local m = mtx[r][lead] + if (mtx[r][lead] ~= 0) then + for u = 1, columnCount do + mtx[r][u] = mtx[r][u] / m + end + augmt[r][1] = augmt[r][1] / m + end + for i = 1, rowCount do + local m = mtx[i][lead] + if (i ~= r) then + for v = 1, columnCount do + mtx[i][v] = mtx[i][v] - m * mtx[r][v] + end + augmt[i][1] = augmt[i][1] - m * augmt[r][1] + end + end + lead = lead + 1 + end + return matrix.concath(mtx, augmt) +end + +function matrix.gauss0E(mtx, augmt, fom, dignum) + local strng = "" + truncate = truncate or 6 + local mtx = matrix.copy(mtx) + local augmt = matrix.copy(augmt) + if matrix.columns(augmt) ~= 1 then + error("The second matrix should have only 1 column.") + end + step = 1 + lead = 1 + stepCnt = 0 + rowCount = #mtx + columnCount = #mtx[1] + for r = 1, rowCount do + if lead > columnCount then + return mtx + end + i = r + while (mtx[i][lead] == 0) do + i = i + 1 + if (i - 1 == rowCount) then + i = r + if (columnCount == lead) then + if stepCnt == 0 then + stepCnt = stepCnt + 1 + strng = + strng .. + "Step " .. + tostring(stepCnt) ".$$" .. + tostring(matrix.show(matrix.concath(mtx, augmt), fom, dignum)) + return strng + end + return strng + end + lead = lead + 1 + end + end + + if i ~= r then + mtx = matrix.swapRows(mtx, i, r) + augmt = matrix.swapRows(augmt, i, r) + stepCnt = stepCnt + 1 + strng = + strng .. + "Step " .. + tostring(stepCnt) .. + ": Interchange rows " .. + tostring(i) .. + " and " .. tostring(r) .. ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$" + end + + local m = mtx[r][lead] + if (mtx[r][lead] ~= 0) then + for u = 1, columnCount do + mtx[r][u] = mtx[r][u] / m + end + augmt[r][1] = augmt[r][1] / m + if m ~= 1.0 then + if m ~= complex("1.0") then + stepCnt = stepCnt + 1 + strng = + strng .. + "Step " .. + tostring(stepCnt) .. + ": Divide row " .. + tostring(r) .. + " by " .. + tostring(complex.round(complex(m), dignum)) .. + ".$$" .. + tostring(matrix.show(matrix.concath(mtx, augmt), fom, dignum)) .. + "$$" + end + end + end + for i = 1, rowCount do + local m = mtx[i][lead] + if (i ~= r) then + for v = 1, columnCount do + mtx[i][v] = mtx[i][v] - m * mtx[r][v] + end + augmt[i][1] = augmt[i][1] - m * augmt[r][1] + if m ~= 0 then + if m ~= complex("0.0") then + stepCnt = stepCnt + 1 + strng = + strng .. + "Step " .. + tostring(stepCnt) .. + ": Multiply row " .. + tostring(r) .. + " by " .. + tostring(complex.round(complex(m), dignum)) .. + " and subtract it from row " .. + tostring(i) .. + ".$$" .. + tostring( + matrix.show(matrix.concath(mtx, augmt), fom, dignum) + ) .. + "$$" + end + end + end + end + lead = lead + 1 + end + return strng +end + +function matrix.rank(m1) + local mtx = {} + mtx = matrix.rref(m1) + rank = #mtx + for i = 1, #mtx do + if CheckEqual(mtx[i], 0) then + rank = rank - 1 + end + end + return rank +end + +function CheckEqual(Values, Number) + local CheckEqual = true + local i = 1 + + while (CheckEqual and (i <= #Values)) do + if Values[i] == Number then + i = i + 1 + else + CheckEqual = false + end + end + + return CheckEqual +end + +function matrix.replace(m1, func, ...) + local mtx = {} + for i = 1, #m1 do + local m1i = m1[i] + local mtxi = {} + for j = 1, #m1i do + mtxi[j] = func(m1i[j], ...) + end + mtx[i] = mtxi + end + return setmetatable(mtx, matrix_meta) +end + +function matrix.show(mtx, format, dig) + mtx = matrix.process(mtx) + local format = format or "bmatrix" + local dig = dig or 6 + local str = "\\begin{" .. format .. "}" + for i = 1, #mtx do + str = str .. "\t" .. complex.round(complex(mtx[i][1]), dig) + for j = 2, #mtx[1] do + str = str .. " & " .. complex.round(complex(mtx[i][j]), dig) + end + if i == #mtx then + str = str .. " \\\\ " + else + str = str .. " \\\\ " + end + end + return str .. "\\end{" .. format .. "} " +end + +matrix_meta.__tostring = function(...) + return matrix.show(...) +end + +matrix_meta.__add = function(...) + return matrix.add(...) +end + +matrix_meta.__sub = function(...) + return matrix.sub(...) +end + +matrix_meta.__mul = function(m1, m2) + if getmetatable(m1) ~= matrix_meta then + return matrix.mulnum(m2, m1) + elseif getmetatable(m2) ~= matrix_meta then + return matrix.mulnum(m1, m2) + end + return matrix.mul(m1, m2) +end + +matrix_meta.__div = function(m1, m2) + if getmetatable(m1) ~= matrix_meta then + return matrix.mulnum(matrix.invert(m2), m1) + elseif getmetatable(m2) ~= matrix_meta then + return matrix.divnum(m1, m2) + end + return matrix.div(m1, m2) +end + +matrix_meta.__unm = function(mtx) + return matrix.mulnum(mtx, -1) +end + +local option = { + ["*"] = function(m1) + return matrix.conjugate(m1) + end, + ["T"] = function(m1) + return matrix.transpose(m1) + end +} +matrix_meta.__pow = function(m1, opt) + return option[opt] and option[opt](m1) or matrix.pow(m1, opt) +end + +-- vector part + +vectors = {} + +vector = {} --module + +local vector_meta = {} + +function vector.new(vector, rows, columns, n) + if columns ~= "e" then + local tbl = {} + for i = 1, #rows do + tbl[i] = rows[i] + end + return setmetatable(tbl, vector_meta) + end + local vec = {} + if columns == "e" then + for i = 1, rows do + if i == n then + vec[i] = 1 + else + vec[i] = 0 + end + end + return setmetatable(vec, vector_meta) + end +end + +setmetatable( + vector, + {__call = function(...) + return vector.new(...) + end} +) + +function vector.add(v1, v2) + if #v1 ~= #v2 then + return error("Vectors should be of same dimension.") + end + local vec = {} + for i = 1, #v1 do + vec[i] = v1[i] + v2[i] + end + return setmetatable(vec, vector_meta) +end + +function vector.sub(v1, v2) + if #v1 ~= #v2 then + return error("Vectors should be of same dimension.") + end + local vec = {} + for i = 1, #v1 do + vec[i] = v1[i] - v2[i] + end + return setmetatable(vec, vector_meta) +end + +function vector.dot(v1, v2) + if #v1 ~= #v2 then + return error("Vectors should be of same dimension") + end + local sum = 0 + for i = 1, #v1 do + sum = sum + v1[i] * complex.conjugate(complex(v2[i])) + end + return sum +end + +function vector.mulnum(v1, num) + local vec = {} + -- multiply elements with number + for i = 1, #v1 do + vec[i] = v1[i] * num + end + return setmetatable(vec, vector_meta) +end + +function vector.sumnorm(v1) + local norm = 0 + for i = 1, #v1 do + norm = norm + complex.abs(complex(v1[i])) + end + return norm +end + +function vector.euclidnorm(v1) + return complex.sqrt(vector.dot(v1, v1)) +end + +function vector.pnorm(v1, p) + if math.floor(p) ~= math.abs(p) or p <= 1 then + return error("Invalid value of p") + end + local sum = 0 + for i = 1, #v1 do + sum = sum + complex.abs(complex(v1[i])) ^ p + end + return sum ^ (1 / p) +end + +function vector.supnorm(v1) + local result = 0 + for i = 1, #v1 do + local e = complex.abs(complex(v1[i])) + if e > result then + result = e + end + end + return result +end + +function vector.cross(v1, v2) + if #v1 ~= 3 or #v2 ~= 3 then + return error("Vectors should be of dimension 3") + end + local vec = {} + vec[1] = v1[2] * v2[3] - v1[3] * v2[2] + vec[2] = v1[3] * v2[1] - v1[1] * v2[3] + vec[3] = v1[1] * v2[2] - v1[2] * v2[1] + return setmetatable(vec, vector_meta) +end + +function vector.createrandom(n, start, stop) + start = start or 0 + stop = stop or 10 + vec = {} + for i = 1, n do + vec[i] = math.random(start, stop) + vec[i] = vec[i] + math.min(math.random(), math.abs(vec[i] - start), math.abs(stop - vec[i])) + end + return setmetatable(vec, vector_meta) +end + +function vector.getcoordinate(vec, i) + if vec[i] then + return vec[i] + end +end + +function vector.setcoordinate(vec, i, val) + if vec[i] then + vec[i] = val + return val + end +end + +function vector.getangle(v1, v2) + if #v1 ~= #v2 then + return error("Vectors should be of same dimension") + end + local x = complex.get(vector.dot(v1, v2) / (vector.euclidnorm(v1) * vector.euclidnorm(v2))) + return math.acos(mathround(x, 15)) +end + +function vector.copy(v1) + local vec = {} + for i = 1, #v1 do + vec[i] = v1[i] + end + return setmetatable(vec, vector_meta) +end + +function vector.op(exp) + return load("return " .. exp, exp, "t", vectors)() +end + +function vector.process(v1) + --v1=load("return "..v1)() + return vector.mulnum(v1, 1.0) +end + +function vector.show(vec, dig) + vec = vector.process(vec) + local dig = dig or 6 + local str = "" + for i = 1, #vec do + if i == 1 then + str = str .. complex.round(complex(vec[i]), dig) + else + str = str .. "," .. complex.round(complex(vec[i]), dig) + end + end + return str .. "" +end + +function vector.parse(vec) + local tbl = {} + for i = 1, #vec do + tbl[i] = vec[i] + end + return "(" .. table.concat(tbl, ",") .. ")" +end + +function vector.gs(inptTbl, brckt, dignum) + local brcktR = "" + brckt = brckt or "round" + if brckt == "round" then + brcktL = "(" + brcktR = ")" + end + if brckt == "square" then + brcktL = "[" + brcktR = "]" + end + if brckt == "curly" then + brcktL = "\\{" + brcktR = "\\}" + end + + local tbl = {} + local str = "" + k = #inptTbl + + if vector.euclidnorm(inptTbl[1]) ~= complex(0.0) then + tbl[1] = vector.mulnum(inptTbl[1], 1 / vector.euclidnorm(inptTbl[1])) + else + tbl[1] = vector.mulnum(inptTbl[1], 1.0) + end + setmetatable(tbl[1], vector_meta) + str = str .. "$\\left" .. brcktL .. vector.show(tbl[1], dignum) .. "\\right" .. brcktR + for i = 2, k do + tbl[i] = inptTbl[i] + setmetatable(tbl[i], vector_meta) + for j = 1, i - 1 do + setmetatable(tbl[j], vector_meta) + tbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j]))) + end + if vector.euclidnorm(tbl[i]) ~= complex(0.0) then + tbl[i] = vector.mulnum(tbl[i], 1 / vector.euclidnorm(tbl[i])) + end + tbl[i] = vector.mulnum(tbl[i], 1.0) + str = str .. ",\\left" .. brcktL .. vector.show(tbl[i], dignum) .. "\\right" .. brcktR + end + str = str .. "$" + return str +end + +function vector.gsX(inptTbl, brckt, dignum) + local brcktR = "" + local cnt = 1 + brckt = brckt or "round" + if brckt == "round" then + brcktL = "\\left(" + brcktR = "\\right)$$" + end + if brckt == "square" then + brcktL = "\\left[" + brcktR = "\\right]$$" + end + if brckt == "curly" then + brcktL = "\\left\\{" + brcktR = "\\right\\}$$" + end + + local tbl = {} + local tmpTbl = {} + local str = "" + k = #inptTbl + str = str .. "\\ \\newline Take given vectors as $v_1,\\ldots, v_" .. k .. "$ in order." + + if vector.euclidnorm(inptTbl[1]) ~= complex(0.0) then + tbl[1] = vector.mulnum(inptTbl[1], 1 / vector.euclidnorm(inptTbl[1])) + else + tbl[1] = vector.mulnum(inptTbl[1], 1.0) + end + setmetatable(tbl[1], vector_meta) + str = str .. "\\ \\newline Step " .. cnt .. ": $$ u_" .. cnt .. "=v_" .. cnt .. "=" + str = str .. brcktL .. vector.show(inptTbl[1], dignum) .. brcktR + str = str .. " $$ e_" .. cnt .. "=" + if vector.euclidnorm(tbl[1]) ~= complex(0.0) then + str = str .. "\\frac{u_{" .. cnt .. "}}" .. "{||u_{" .. cnt .. "}||} =" + end + str = str .. brcktL .. vector.show(tbl[1], dignum) .. brcktR + for i = 2, k do + tbl[i] = inptTbl[i] + setmetatable(tbl[i], vector_meta) + for j = 1, i - 1 do + setmetatable(tbl[j], vector_meta) + tmpTbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j]))) + tbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j]))) + end + if vector.euclidnorm(tbl[i]) ~= complex(0.0) then + tbl[i] = vector.mulnum(tbl[i], 1 / vector.euclidnorm(tbl[i])) + else + tbl[i] = vector.mulnum(tbl[i], 1.0) + end + + cnt = cnt + 1 + str = str .. " Step " .. cnt + str = str .. ": $$ u_" .. cnt .. "=" + str = str .. "v_" .. cnt .. "-\\sum_{j=1}^{" .. (cnt - 1) .. "}{{proj_{u_j}(v_" .. cnt .. ")}}=" + str = str .. brcktL .. vector.show(tmpTbl[i], dignum) .. brcktR + str = str .. " $$ e_" .. cnt .. "=" + if vector.euclidnorm(tbl[i]) ~= complex(0.0) then + str = str .. "\\frac{u_{" .. cnt .. "}}" .. "{||u_{" .. cnt .. "}||} =" + end + str = str .. brcktL .. vector.show(tbl[i], dignum) .. brcktR + end + + return str +end + +vector_meta.__tostring = function(...) + return vector.show(...) +end + +vector_meta.__add = function(...) + return vector.add(...) +end + +vector_meta.__sub = function(...) + return vector.sub(...) +end + +vector_meta.__unm = function(vec) + return vector.mulnum(vec, -1) +end + +vector_meta.__mul = function(v1, v2) + if getmetatable(v1) ~= vector_meta then + return vector.mulnum(v2, v1) + elseif getmetatable(v2) ~= vector_meta then + return vector.mulnum(v1, v2) + end + return vector.dot(v1, v2) +end + +function mathround(num, numDecimalPlaces) + local mult = 10 ^ (numDecimalPlaces or 0) + return math.floor(num * mult + 0.5) / mult +end + + +\end{luacode*} + +% matrix latex commands + +\newcommand\matrixNew[2]{% + \directlua{% + matrices['#1'] = matrix(#2) + }% +} + +% ========= KEY DEFINITIONS ========= +\define@key{matrixop}{type}{\def\mop@type{#1}} +\define@key{matrixop}{truncate}{\def\mop@truncate{#1}} + +% ========= KEY DEFAULTS ========= +\setkeys{matrixop}{type=bmatrix,truncate=6}% + +\newcommand{\matrixPrint}[2][]{% + \begingroup% + \setkeys{matrixop}{#1} + \directlua{tex.sprint(matrix.show(matrices['#2'],"\mop@type",\mop@truncate))} + % + \endgroup% +} + +\newcommand\matrixOp[2]{% + \directlua{% + matrices['#1'] = matrix.op('#2') + }% +} + + +\newcommand\matrixAdd[3]{% + \directlua{% + matrices['#1'] = matrix.add(matrices['#2'],matrices['#3']) + }% +} + +\newcommand\matrixSub[3]{% + \directlua{% + matrices['#1'] = matrix.sub(matrices['#2'],matrices['#3']) + }% +} + +\newcommand\matrixMulNum[3]{% + \directlua{% + matrices['#1'] = matrix.mulnum(matrices['#3'],#2) + }% +} + +\newcommand\matrixMul[3]{% + \directlua{% + matrices['#1'] = matrix.mul(matrices['#2'],matrices['#3']) + }% +} + +\newcommand\matrixSwapRows[4]{% + \directlua{% + matrices['#1'] = matrix.swapRows(matrices['#2'],#3,#4) + }% +} + +\newcommand\matrixSwapCols[4]{% + \directlua{% + matrices['#1'] = matrix.swapCols(matrices['#2'],#3,#4) + }% +} + +\newcommand\matrixMulRow[4]{% + \directlua{% + matrices['#1'] = matrix.mulRow(matrices['#2'],#3,#4) + }% +} + +\newcommand\matrixMulCol[4]{% + \directlua{% + matrices['#1'] = matrix.mulCol(matrices['#2'],#3,#4) + }% +} + +\newcommand\matrixMulAddRow[5]{% + \directlua{% + matrices['#1'] = matrix.mulAddRow(matrices['#2'],#4,#3,#5) + }% +} + +\newcommand\matrixMulAddCol[5]{% + \directlua{% + matrices['#1'] = matrix.mulAddCol(matrices['#2'],#4,#3,#5) + }% +} + +\newcommand\matrixTranspose[2]{% + \directlua{% + matrices['#1'] = matrix.transpose(matrices['#2']) + }% +} + +\newcommand\matrixSubmatrix[6]{% + \directlua{% + matrices['#1'] = matrix.subm(matrices['#2'],#3,#4,#5,#6) + }% +} + +\newcommand\matrixConcatH[3]{% + \directlua{% + matrices['#1'] = matrix.concath(matrices['#2'],matrices['#3']) + }% +} + +\newcommand\matrixConcatV[3]{% + \directlua{% + matrices['#1'] = matrix.concatv(matrices['#2'],matrices['#3']) + }% +} + +\newcommand\matrixNumRows[1]{% + \directlua{% + tex.sprint(tostring(matrix.rows(matrices['#1']))) + }% +} + +\newcommand\matrixNumCols[1]{% + \directlua{% + tex.sprint(tostring(matrix.columns(matrices['#1']))) + }% +} + +\newcommand\matrixGetElement[3]{% + \directlua{% + tex.sprint(tostring(matrix.getelement(matrices['#1'],#2,#3))) + }% +} + +\newcommand\matrixSetElement[4]{% + \directlua{% + matrix.setelement(matrices['#1'],#2,#3,#4) + }% +} + +\newcommand\matrixInvert[2]{% + \directlua{% + matrices['#1'] = matrix.invert(matrices['#2']) + }% +} + +\newcommand\matrixPow[3]{% + \directlua{% + matrices['#1'] = matrix.pow(matrices['#2'],#3) + }% +} + +\newcommand\matrixCreateRandom[5]{% + \directlua{% + matrices['#1'] = matrix.createrandom(#2,#3,#4,#5) + }% +} + +\newcommand\matrixDet[1]{% + \directlua{% + tex.sprint(tostring(matrix.det(matrices['#1']))) + }% +} + +\newcommand\matrixTrace[1]{% + \directlua{% + tex.sprint(tostring(matrix.trace(matrices['#1']))) + }% +} + +\newcommand\matrixNormOne[1]{% + \directlua{% + tex.sprint(tostring(matrix.norm1(matrices['#1']))) + }% +} + +\newcommand\matrixNormInfty[1]{% + \directlua{% + tex.sprint(tostring(matrix.norminfty(matrices['#1']))) + }% +} + +\newcommand\matrixNormMax[1]{% + \directlua{% + tex.sprint(tostring(matrix.normmax(matrices['#1']))) + }% +} + +\newcommand\matrixNormF[1]{% + \directlua{% + tex.sprint(tostring(matrix.normF(matrices['#1']))) + }% +} + +\newcommand\matrixCopy[2]{% + \directlua{% + matrices['#1'] = matrix.copy(matrices['#2']) + }% +} + +\newcommand\matrixRREF[2]{% + \directlua{% + matrices['#1'] = matrix.rref(matrices['#2']) + }% +} + +\newcommand\matrixConjugate[2]{% + \directlua{% + matrices['#1'] = matrix.conjugate(matrices['#2']) + }% +} + +\newcommand\matrixConjugateT[2]{% + \directlua{% + matrices['#1'] = matrix.conjugateT(matrices['#2']) + }% +} + +\newcommand\matrixRank[1]{% + \directlua{% + tex.sprint(tostring(matrix.rank(matrices['#1']))) + }% +} + +\newcommand\matrixRREFERR[1]{% + \directlua{% + tex.sprint(tostring(matrix.rref0E(matrices['#1']))) + }% +} + +\newcommand\matrixRREFE[1]{% + \directlua{% + tex.sprint(tostring(matrix.rref0E(matrices['#1']))) + }% +} + +% ========= KEY DEFINITIONS ========= +\define@key{matrixrr}{type}{\def\moprr@type{#1}} +\define@key{matrixrr}{truncate}{\def\moprr@truncate{#1}} + +% ========= KEY DEFAULTS ========= +\setkeys{matrixrr}{type=bmatrix,truncate=6}% + +\newcommand{\matrixRREFSteps}[2][]{% + \begingroup% + \setkeys{matrixrr}{#1} + \directlua{% + tex.sprint(matrix.rref0E(matrices['#2'],"\moprr@type",\moprr@truncate))} + % + \endgroup% +} + +\newcommand\matrixGaussJordan[3]{% + \directlua{% + matrices['#1'] = matrix.GaussJordan(matrices['#2'],matrices['#3']) + }% +} + +\newcommand{\matrixGaussJordanSteps}[3][]{% + \begingroup% + \setkeys{matrixrr}{#1} + \directlua{% + tex.sprint(matrix.gauss0E(matrices['#2'],matrices['#3'],"\moprr@type",\moprr@truncate))} + % + \endgroup% +} + +% vector latex commands + +\newcommand\vectorNew[2]{% + \directlua{% + vectors['#1'] = vector(#2) + }% +} + +% ========= KEY DEFINITIONS ========= +\define@key{vectorop}{truncate}{\def\vop@truncate{#1}} + +% ========= KEY DEFAULTS ========= +\setkeys{vectorop}{truncate=6}% + +\newcommand{\vectorPrint}[2][]{% + \begingroup% + \setkeys{vectorop}{#1} + \directlua{tex.sprint(vector.show(vectors['#2'],\vop@truncate))} + % + \endgroup% +} + +\newcommand\vectorParse[1]{% + \directlua{% + tex.sprint(tostring(vector.parse(vectors['#1']))) + }% +} + +\newcommand\vectorOp[2]{% + \directlua{% + vectors['#1'] = vector.op('#2') + }% +} + +\newcommand\vectorAdd[3]{% + \directlua{% + vectors['#1'] = vector.add(vectors['#2'],vectors['#3']) + }% +} + +\newcommand\vectorSub[3]{% + \directlua{% + vectors['#1'] = vector.sub(vectors['#2'],vectors['#3']) + }% +} + +\newcommand\vectorDot[2]{% + \directlua{% + tex.sprint(tostring(vector.dot(vectors['#1'],vectors['#2']))) + }% +} + +\newcommand\vectorMulNum[3]{% + \directlua{% + vectors['#1'] = vector.mulnum(vectors['#2'],#3) + }% +} + +\newcommand\vectorCross[3]{% + \directlua{% + vectors['#1'] = vector.cross(vectors['#2'],vectors['#3']) + }% +} + +\newcommand\vectorSumNorm[1]{% + \directlua{% + tex.sprint(tostring(vector.sumnorm(vectors['#1']))) + }% +} + +\newcommand\vectorEuclidNorm[1]{% + \directlua{% + tex.sprint(tostring(vector.euclidnorm(vectors['#1']))) + }% +} + +\newcommand\vectorSupNorm[1]{% + \directlua{% + tex.sprint(tostring(vector.supnorm(vectors['#1']))) + }% +} + +\newcommand\vectorpNorm[2]{% + \directlua{% + tex.sprint(tostring(vector.pnorm(vectors['#1'],#2))) + }% +} + +\newcommand\vectorCreateRandom[4]{% + \directlua{% + vectors['#1'] = vector.createrandom(#2,#3,#4) + }% +} + +\newcommand\vectorCopy[2]{% + \directlua{% + vectors['#1'] = vector.copy(vectors['#2']) + }% +} + +\newcommand\vectorGetCoordinate[2]{% + \directlua{% + tex.sprint(tostring(vector.getcoordinate(vectors['#1'],#2))) + }% +} + +\newcommand\vectorSetCoordinate[3]{% + \directlua{% + tex.sprint(tostring(vector.setcoordinate(vectors['#1'],#2,#3))) + }% +} + +\newcommand\vectorGetAngle[2]{% + \directlua{% + tex.sprint(tostring(vector.getangle(vectors['#1'],vectors['#2']))) + }% +} + +\newcommand\complexRound[2]{% + \directlua{% + tex.sprint(tostring(complex.round(complex('#1'),#2))) + }% +} + +% ========= KEY DEFINITIONS ========= +\define@key{vecrr}{brckt}{\def\voprr@brckt{#1}} +\define@key{vecrr}{truncate}{\def\voprr@truncate{#1}} + +% ========= KEY DEFAULTS ========= +\setkeys{vecrr}{brckt=round,truncate=6}% +\newcommand{\vectorGramSchmidt}[2][]{% + \begingroup% + \setkeys{vecrr}{#1} + \directlua{% + local tbl = #2 + local outTbl={} + local sum = 0 + for i=1,table.getn(tbl) do + outTbl[i] = vectors[tbl[i]] + end + + tex.sprint(vector.gs(outTbl,"\voprr@brckt",\voprr@truncate))} + % + \endgroup% +} + +\newcommand{\vectorGramSchmidtSteps}[2][]{% + \begingroup% + \setkeys{vecrr}{#1} + \directlua{% + local tbl = #2 + local outTbl={} + local sum = 0 + for i=1,table.getn(tbl) do + outTbl[i] = vectors[tbl[i]] + end + tex.sprint(vector.gsX(outTbl,"\voprr@brckt",\voprr@truncate))} + % + \endgroup% +} + +\endinput diff --git a/macros/luatex/latex/lualinalg/lualinalg.tex b/macros/luatex/latex/lualinalg/lualinalg.tex new file mode 100644 index 0000000000..fa7c9fa4ea --- /dev/null +++ b/macros/luatex/latex/lualinalg/lualinalg.tex @@ -0,0 +1,1084 @@ +\documentclass{article} +\usepackage{listings,color,parskip,booktabs,longtable,array, +hyperref,multirow,multicol,url,amsmath,amssymb,framed,graphicx} +\usepackage[top=1.1in, bottom=1.1in, left=1in, right=1in]{geometry} +\hypersetup{colorlinks,urlcolor=blue} +\lstset{frame=none, + language=[LaTeX]{TeX}, + aboveskip=3mm, + belowskip=3mm, + showstringspaces=false, + columns=flexible, + basicstyle={\ttfamily}, + numbers=none, + numberstyle=\tiny\color{gray}, + stringstyle=\color{mauve}, + breaklines=true, + breakatwhitespace=true, + tabsize=1, + upquote=true +} +\begin{document} +\title{The lualinalg Package} +\author{Chetan Shirore and Ajit Kumar} +\maketitle + +\section{Introduction} + +The \verb|lualinalg| package is developed to perform operations on vectors and matrices defined over the field of real or complex numbers inside LaTeX documents. It provides flexible ways for defining and displaying vectors and matrices. No particular environment of LaTeX is required to use commands in the package. The package is written in Lua, and tex file is to be compiled with the LuaLaTeX engine. The time required for calculations is not an issue while compiling with LuaLaTeX. There is no need to install Lua on the user's system as TeX distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. It may also save users' efforts to copy vectors and matrices from other software (which may not be in latex-compatible format) and to use them in a tex file. The vectors and matrices of reasonable size can be handled with ease. The package can be modified or extended by writing custom Lua programs (Section \ref{customuse}). + +\section{Installation and License} +The installation of the \verb|lualinalg| package is similar to the plain latex package, where the \verb|.sty| file is in the LaTeX directory of the texmf tree. The package can be included with \verb|\usepackage{lualinalg}| command in the preamble of the LaTeX document. + +The \verb|lualinalg| package is released under the LaTeX Project Public License v1.3c or later. The complete license text is available at \url{http://www.latex-project.org/lppl.txt}. It is developed in Lua. Lua is available as a certified open-source software. Its license is simple and liberal, which is compatible with GPL. The package makes use of \verb|complex.lua| file which is available on \url{https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua}. It is available under the same licensing as that of Lua. The package also loads the \href{https://ctan.org/pkg/luamaths}{luamaths} package, which is available under the LaTeX Project Public License v1.3c or later. This package is loaded to use the standard mathematical functions and for computations on real numbers while performing operations on vectors and matrices. +\section{Defining vectors and performing operations on vectors} +\subsection{Defining Vectors} Vectors are defined with the \verb|\vectornew| command. +\begin{verbatim} +\vectorNew{vector name}{coordinates} +\end{verbatim} + This command has two compulsory arguments: \verb|vector name| and \verb|coordinates|. Coordinates of vectors are enclosed in curly braces. A comma separates coordinates. The complex numbers are to be enclosed in single or double quotes inside the \verb|complex()| function. The following are a few valid ways of defining vectors. +\begin{lstlisting} +\vectorNew{v1}{{1,2,3,4,5,6}} +\vectorNew{v2}{{3,6,complex('6+6i')}} +\end{lstlisting} +The standard vector of dimension \(n \) with \(i^{th}\) coordinate \(1\) can be produced by using the following command. +\begin{lstlisting} +\vectorNew{e}{n,'e',i} +\end{lstlisting} +For example, the following commands +\begin{lstlisting} +\vectorNew{e_1}{3,'e',1} +\(e_1=\left(\vectorPrint{e}\right)\) +\end{lstlisting} +output to \(e_1 = \left(1.0,0.0,0.0\right) \). +\subsection{Commands for operations on vectors} +Table \ref{tbl:luavector} lists commands for operations on vectors. +\begin{longtable}{m{7cm}m{7cm}} +\toprule +\multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\ +\toprule +\begin{lstlisting} +\vectorPrint[truncate]{vector} +\end{lstlisting} & Prints vector. Accepts one \emph{optional} argument: \verb|truncate|. It specifies the number of digits up to which vector coordinates must be truncated. The value of \verb|truncate| may be 0,1,2,\ldots\\ +\midrule +\begin{lstlisting} +\vectorGetCoordinate{vector}{i} +\end{lstlisting} +& +Gives the \(i^{th}\) coordinate of vector. \\ +\midrule + \begin{lstlisting} +\vectorSetCoordinate +{vector}{i}{val} +\end{lstlisting} +& +Sets the \(i^{th}\) coordinate of vector as \verb|val|. \\ +\midrule +\begin{lstlisting} +\vectorCopy{v}{w} +\end{lstlisting}& +Defines a new vector \(v\) obtained by copying coordinates of vector \(w\). \\ +\midrule +\begin{lstlisting} +\vectorAdd{vector}{v1}{v2} +\end{lstlisting}& +Defines a new vector as the addition of vectors \(v1\) and \(v2\). Both vectors \(v1\) and \(v2\) should be of the same dimension. The addition is done coordinate-wise.\\ +\midrule + \begin{lstlisting} +\vectorSub{vector}{v1}{v2} +\end{lstlisting}& +Defines a new vector as the subtraction of vectors \(v1\) and \(v2\). Both vectors \(v1\) and \(v2\) should be of the same dimension. The subtraction is done coordinate-wise. \\ +\midrule + \begin{lstlisting} +\vectorMulNum{vector}{v}{num} +\end{lstlisting}& +Defines a new vector obtained by multiplying each coordinate of a vector by number \verb|num|. It can be a real or complex number (scalar). \\ +\midrule +\begin{lstlisting} +\vectorDot{v}{w} +\end{lstlisting}& +Gives the dot product of two vectors: \(v\) and \(w\). If \(v=\left(v_1, \ldots, v_n \right)\) and \(w =\left(w_1, \ldots, w_n \right)\) are defined over the field of real numbers, then it is evaluated as \(v_1\cdot w_1 + \cdots + v_n \cdot w_n\). If they are defined over the field of complex numbers, then it is evaluated as \(v_1\cdot \bar{w_1} + \cdots + v_n \cdot \bar{w_n}\). \(\bar{w_i}\) denotes the complex conjugate of complex number \(w_i\). \\ +\midrule +\begin{lstlisting} +\vectorCross{vector}{v}{w} +\end{lstlisting}& +Defines a new vector obtained by taking the cross product of vectors \(v\) and \(w\) of dimension 3. If \(v=\left(v_1, v_2, v_3 \right)\) and \(w =\left(w_1, w_2, w_3 \right)\), then the cross product of these two vectors is the vector \((v_2w_3-v_3w_2, v_3w_1-v_1w_3,\) \( v_1w_2-v_2w_1 ) \). \\ +\midrule + \begin{lstlisting} +\vectorSumNorm{v} +\end{lstlisting}& +Calculates the sum norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(|v_1| + \cdots + |v_n| \). \\ +\midrule + \begin{lstlisting} +\vectorEuclidNorm{v} +\end{lstlisting}& +Calculates the Euclidean norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(\sqrt{|v_1|^2 + \cdots + |v_n|^2} \). \\ +\midrule + \begin{lstlisting} +\vectorpNorm{v} +\end{lstlisting}& +Calculates the \(p\) \((p > 1)\) norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(\sqrt[p]{|v_1|^2 + \cdots + |v_n|^2} \). \\ +\midrule +\begin{lstlisting} +\vectorSupNorm{v} +\end{lstlisting}& +Calculates the sup norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(\max\{|v_1| , \ldots , |v_n| \} \). \\ +\midrule + \begin{lstlisting} +\vectorCreateRandom{v}{n}{a}{b} +\end{lstlisting}& +Creates a new vector \(v\) of dimension \(n\) with coordinates as random numbers from the interval \([a,b]\). \\ +\midrule +\begin{lstlisting} +\vectorOp{vector}{expression} +\end{lstlisting}& +Defines a new vector obtained by evaluating an expression. The expression supports all standard operations such as \(+,-,* \). \\ +\midrule + \begin{lstlisting} + \vectorGetAngle{v}{w} +\end{lstlisting}& +Gives the angle between two vectors \(v\) and \(w\) in radians. If \(v\) and \(w \) are defined over the field of real numbers, then it is evaluated as \(\cos^{-1}\left(\frac{v \cdot w}{|v| |w|}\right)\). If they are defined over the field of complex numbers, then it is evaluated as \(\cos^{-1}\left(\frac{Re (v \cdot w) }{|v| |w|}\right)\). Here \(v \cdot w\) denotes the dot product of vectors \(v\) and \(w\), \(Re (v \cdot w)\) denotes real part of the dot product \(v \cdot w\), and \(|v|\) and \(|w|\) denote Euclidean norms of vectors \(v\) and \(w\) respectively. \\ +\midrule + \begin{lstlisting} +\vectorParse{vector} +\end{lstlisting}& +Parses the coordinates of a vector defined over the field of real numbers. The command helps to plot vectors with different packages. \\ +\midrule +\begin{lstlisting} +\vectorGramSchmidt[brckt, +truncate]{list of vectors} +\end{lstlisting} & Performs Gram Schmidt orthogonalisation process on a list of vectors. Accepts two \emph{optional} arguments: \verb|brckt| and \verb|truncate|. The \verb|brckt| is type of parenthesis to be used for displaying vectors. It can be `round', `square' or `curly'. The truncate is number of digits up to which vector coordinates are to be truncated. The value of \verb|truncate| can be 0,1,2,\ldots\\ +\midrule +\begin{lstlisting} +\vectorGramSchmidtSteps[brckt, +truncate]{list of vectors} +\end{lstlisting} & Performs Gram Schmidt orthogonalisation process on a list of vectors in a step-by-step manner. Accepts two \emph{optional} arguments: \verb|brckt| and \verb|truncate|. The \verb|brckt| is type of parenthesis to be used for displaying vectors. It can be `round', `square' or `curly'. The truncate is number of digits up to which vector coordinates are to be truncated. The value of \verb|truncate| can be 0,1,2,\ldots\\ +\bottomrule \\ +\caption{Commands for operations on vectors} +\label{tbl:luavector} +\end{longtable} +\subsection{Illustrations of commands for operations on vectors} +The following commands define vectors \(v,w,x,\) and \(y\). +\begin{lstlisting} +\vectorNew{v}{{1,2,complex('3+3i')}} +\vectorNew{w}{{3,6,complex('6+6i')}} +\vectorNew{x}{{1.12345678,6,complex('6+6i')}} +\vectorNew{y}{{1,2,3}} +\end{lstlisting} +Table \ref{tbl:illluavector} illustrates various operations on vectors \(v,w,x\) and \(y\). +\begin{longtable}{lc} +\toprule +Commands & Output Produced\\ +\toprule +\begin{lstlisting} +\(v=\left(\vectorPrint{v}\right)\) +\(w=\left(\vectorPrint{w}\right)\) +\end{lstlisting} & +\(v=\left(1.0,2.0,3.0+3.0i\right)\) \\ +& +\(w=\left(3.0,6.0,6.0+6.0i\right)\) +\\ +\midrule +\begin{lstlisting} +\(x=\left(\vectorPrint +[truncate=3]{x}\right)\) +\end{lstlisting} & +\(x=\left(1.123,6.0,6.0+6.0i\right)\) +\\ +\midrule +\begin{lstlisting} +third coordinate of vector +\(v = \vectorGetCoordinate{v}{3}\) +\end{lstlisting} & +third coordinate of vector \(v = 3 + 3i\) +\\ +\midrule +\begin{lstlisting} +\(y = \vectorCopy{y}{w}\) +\(\left(\vectorPrint{y}\right)\) +\end{lstlisting} & +\(y = \left( 3.0,6.0,6.0+6.0i\right)\) +\\ +\midrule +\begin{lstlisting} +new third coordinate of vector +\(y = \vectorSetCoordinate{y}{3}{9.3}\) +\(y=\left(\vectorPrint{y}\right)\) +\end{lstlisting} & +new third coordinate of vector \(y = 9.3\) \\ +& \(y = \left( 3.0,6.0,9.3\right)\) +\\ +\midrule +\begin{lstlisting} +\vectorAdd{v1}{v}{w} +\(v1 = v+w =\left(\vectorPrint{v1}\right)\) +\end{lstlisting} & +\(v1 = v+w =\left(4.0, 8.0, 9.0 + 9.0i\right)\) +\\ +\midrule +\begin{lstlisting} +\vectorSub{v2}{v}{w} +\(v2 = v-w =\left(\vectorPrint{v2}\right)\) +\end{lstlisting} & +\(v2 = v-w =\left(-2.0, -4.0, -3.0 -3.0i\right)\) +\\ +\midrule +\begin{lstlisting} +\vectorMulNum{v3}{v}{complex('3+i')} +\(v3 = 3v =\left(\vectorPrint{v3}\right)\) +\end{lstlisting} & +\(v3 = 3v =\left(3.0 + i, 6.0 + 2.0i, 6.0 + 12.0i\right)\) +\\ +\midrule +\begin{lstlisting} +\vectorDot{v}{w} +\(v \cdot w =\vectorDot{v}{w}\) +\end{lstlisting} & +\(v \cdot w = 51\) +\\ +\midrule +\begin{lstlisting} +\vectorCross{v4}{v}{w} +\(v \times w =\left(\vectorPrint{v4}\right)\) +\end{lstlisting} & +\(v \times w = \left(-6.0 - 6.0i, 3.0 + 3.0i, 0.0\right)\) +\\ +\midrule +\begin{lstlisting} + Sum norm of a vector \(v = \vectorSumNorm{v}\) +\end{lstlisting} & + Sum norm of a vector \(v = 7.2426406871193\) +\\ +\midrule +\begin{lstlisting} +Euclidean norm of a vector + \(v = \vectorEuclidNorm{v}\) +\end{lstlisting} & +Euclidean norm of a vector \(v = 4.7958315233127\) +\\ +\midrule +\begin{lstlisting} +p norm of a vector \(v = \vectorpNorm{v}{3}\) +\end{lstlisting} & +p norm of a vector \(v = 4.4031577258332\) +\\ +\midrule +\begin{lstlisting} +Sup norm of a vector \(v = \vectorSupNorm{v}\) +\end{lstlisting} & +Sup norm of a vector \(v = 4.2426406871193\) +\\ +\midrule +\begin{lstlisting} +\vectorCreateRandom{v5}{3}{9}{90} +\(v5 =\left(\vectorPrint{v5}\right)\) +\end{lstlisting} & +\(v5 =\left(18.290405, 23.356018, 49.966278\right)\) +\\ +\midrule +\begin{lstlisting} +\vectorOp{v6}{v+w-2*v} +\(v6 =\left(\vectorPrint{v7}\right)\) +\end{lstlisting} & +\(v6=\left(2.0, 4.0, 27.0 + 27.0i \right)\) +\\ +\midrule +\begin{lstlisting} + angle between vector \(v\) and \(w\) is + \( \vectorGetAngle{v}{w}\). +\end{lstlisting} & +angle between vector \(v\) and \(w\) is + \( 0.32823410158508\). +\\ +\midrule +\begin{lstlisting} +\vectorParse{y} +\end{lstlisting} & +\(\left(1,2,3 \right)\) +\\ +\bottomrule \\ +\caption{Illustration of commands for operations on vectors} +\label{tbl:illluavector} +\end{longtable} +The package has commands for performing Gram Schmidt Orthogonalisation process. It can also produce the computations in a step-by step manner. +\begin{framed} +\begin{lstlisting}[label={code:luavecgs}, caption={Gram Schmidt Orthogonalisation process in the lualinalgpackage}] +\vectorNew{v1}{{1,2,3}} +\vectorNew{v2}{{4,5,6}} +\vectorNew{v3}{{7,8,90}} +\[v1=\left(\vectorPrint{v1}\right)\] +\[v2=\left(\vectorPrint{v2}\right)\] +\[v3=\left(\vectorPrint{v3}\right)\] +Gram Schmidt on \(v1,v2,v3\): \vectorGramSchmidt[brckt=round,truncate=3]{{'v1','v2','v3'}} +\vectorGramSchmidtSteps[brckt=round,truncate=3]{{'v1','v2','v3'}} +\end{lstlisting} +\end{framed} +Listing \ref{code:luavecgs} outputs the following. +\begin{framed} +\[v1=\left(1,2,3\right)\] +\[v2=\left(4,5,6\right)\] +\[v3=\left(7,8,90\right)\] +Gram Schmidt on \(v1,v2,v3\): $\left(0.267,0.535,0.802\right),\left(0.873,0.218,-0.436\right),\left(0.408,-0.816,0.408\right)$ + +Take given vectors as $v_1,\ldots, v_3$ in order.\ \newline Step 1: $$ u_1=v_1=\left(1.0,2.0,3.0\right)$$ $$ e_1=\frac{u_{1}}{||u_{1}||} =\left(0.267,0.535,0.802\right)$$ Step 2: $$ u_2=v_2-\sum_{j=1}^{1}{{proj_{u_j}(v_2)}}=\left(1.714,0.429,-0.857\right)$$ $$ e_2=\frac{u_{2}}{||u_{2}||} =\left(0.873,0.218,-0.436\right)$$ Step 3: $$ u_3=v_3-\sum_{j=1}^{2}{{proj_{u_j}(v_3)}}=\left(13.5,-27.0,13.5\right)$$ $$ e_3=\frac{u_{3}}{||u_{3}||} =\left(0.408,-0.816,0.408\right)$$ +\end{framed} + +In addition to \verb|\mathRound|, the command \verb|complexRound| is also available. It has the following syntax. +\begin{verbatim} +\complexRound{complex number}{number of decimal places} +\end{verbatim} + +This command has two compulsory arguments. The complex number and number of decimal places to which number should be rounded off. For example, + \verb| \complexRound{3.3333666+6.777666i}{3}| outputs to \(3.333+6.778i\). This command can be nested with other commands in the package. + +\subsection{Plotting vectors} +The \verb|lualinalg| package can be used with other packages that have facility to plot vectors defined over the field of real numbers in 2 or 3 dimensions. Listing \ref{code:luavecplot} illustrates plotting of vectors in 2-D plane by using \verb|lualinalg| and \verb|tikz| package. +\begin{lstlisting}[label={code:luavecplot}, caption={Plotting vectors in 2-dimensions with the lualinalg and tikz packages}] +\begin{document} +\tdplotsetmaincoords{0}{0} +\begin{tikzpicture}[scale=1, + tdplot_main_coords, + axis/.style={->,blue,thick}, + vector/.style={-stealth,red,very thick}, + vector guide/.style={dashed,red,thick}] +\vectorNew{o}{{0,0}} +\vectorNew{e1}{{4,0}} +\vectorNew{e2}{{0,4}} +\vectorNew{f}{{2,1}} +\vectorNew{g}{{1,2}} +% Axes +\draw [axis] \vectorParse{o}-- \vectorParse{e1} node [below left] {$x$}; +\draw [axis] \vectorParse{o}-- \vectorParse{e2} node [right] {$y$}; +% Plotting Vectors +\draw [vector] \vectorParse{o} --\vectorParse{f}; +\draw [vector] \vectorParse{o} --\vectorParse{g}; +\vectorOp{h}{f+g} +\draw [vector] \vectorParse{o} --\vectorParse{h}; +\draw [vector,dashed,black] \vectorParse{f} --\vectorParse{h}; +\draw [vector,dashed,black] \vectorParse{g} --\vectorParse{h}; +% Labels + \node [below right] at \vectorParse{f} {$f$}; + \node [above left] at \vectorParse{g} {$g$}; +\node [above left] at \vectorParse{h} {$f+g$}; + \draw[vector guide, black] \vectorParse{h} -- (\vectorGetCoordinate{h}{1},0) node [below] {$x=\vectorGetCoordinate{h}{1}$}; + \draw[vector guide, black] \vectorParse{h} -- (0,\vectorGetCoordinate{h}{2}) node [left] {$y=\vectorGetCoordinate{h}{2}$}; +\end{tikzpicture} +\end{document} +\end{lstlisting} +Listing \ref{code:luavecplot} produces figure \ref{fig:2dvecplot}. +\begin{figure}[!ht] % or [H] to turn off float + \centering + \includegraphics[scale=0.9]{2dvec.jpg} + \caption{Plotting of 3-D Vectors with lualinalg and tikz packages} + \label{fig:2dvecplot} +\end{figure} +Listing \ref{code:luavecplot2} illustrates plotting of vectors in 3-D plane by using \verb|lualinalg| and \verb|tikz| package. +\begin{lstlisting}[label={code:luavecplot2}, caption={Plotting vectors in 3-dimensions with the lualinalg and tikz packages}] +\documentclass{article} +\usepackage{tikz,tikz-3dplot,lualinalg} +\begin{document} +\tdplotsetmaincoords{60}{120} +\begin{tikzpicture}[scale=1, + tdplot_main_coords, + axis/.style={->,blue,thick}, + vector/.style={-stealth,red,very thick}, + vector guide/.style={dashed,red,thick}] +\vectorNew{o}{{0,0,0}} +\vectorNew{e1}{{3,0,0}} +\vectorNew{e2}{{0,5,0}} +\vectorNew{e3}{{0,0,4}} +\vectorNew{f}{{2,2,0}} +\vectorNew{g}{{-1,2,2}} +% Axes +\draw [axis] \vectorParse{o}-- \vectorParse{e1} node [below left] {$x$}; +\draw [axis] \vectorParse{o}-- \vectorParse{e2} node [right] {$y$}; +\draw [axis] \vectorParse{o}-- \vectorParse{e3} node [above] {$z$}; +% Plotting Vectors +\draw [vector] \vectorParse{o} --\vectorParse{f}; +\draw [vector] \vectorParse{o} --\vectorParse{g}; +\vectorOp{h}{f+g} +\draw [vector] \vectorParse{o} --\vectorParse{h}; +% Labels + \node [below right] at \vectorParse{f} {$f$}; + \node [above left] at \vectorParse{g} {$g$}; +\node [right] at \vectorParse{h} {$f+g$}; + \draw[vector guide, black] \vectorParse{h} -- (\vectorGetCoordinate{h}{1},0,0) node [left] {$x=\vectorGetCoordinate{h}{1}$}; + \draw[vector guide, black] \vectorParse{h} -- (0,\vectorGetCoordinate{h}{2},0) node [below] {$y=\vectorGetCoordinate{h}{2}$}; + \draw[vector guide, black] \vectorParse{h} -- (0,0,\vectorGetCoordinate{h}{3}) node [left] {$z=\vectorGetCoordinate{h}{3}$}; +\end{tikzpicture} +\end{document} +\end{lstlisting} + +Listing \ref{code:luavecplot2} produces figure \ref{fig:3dvecplot}. +\begin{figure}[!ht] % or [H] to turn off float + \centering + \includegraphics[scale=0.9]{3dvec.jpg} + \caption{Plotting of Vectors with lualinalg and tikz packages} + \label{fig:3dvecplot} +\end{figure} + +\section{Defining matrices and operations on matrices} +Matrices are defined with the \verb|\matrixNew| command. +\begin{lstlisting} +\matrixNew{matrix name}{row entries} +\end{lstlisting} +This command has two compulsory arguments: \verb|matrix name| and \verb|row entries|. Each row of the matrix is enclosed in curly brackets. A comma separates numbers in rows. Rows are also separated by a comma. The whole matrix is then enclosed in curly brackets. The complex numbers are to be enclosed in single or double quotes inside the parenthesis of the \verb|complex()| function. The following are a few valid ways of defining matrices. + +\begin{lstlisting} +\def\n{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}} +\def\s{{{1,2,3},{4,5,6},{7,8,10}}} +\matrixNew{m}{\n} +\matrixNew{n}{\s} +% an alternative way +\matrixNew{m}{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}} +\matrixNew{n}{{{1,2,3},{4,5,6},{7,8,10}}} +\end{lstlisting} + +The identity matrix can be defined as well by using the \verb|\matrixNew| command. For example, the following commands +\begin{lstlisting} +\matrixNew{mtx}{3,'I'} +I = \(\matrixPrint{mtx}\) +\end{lstlisting} +output to +\[I = \begin{bmatrix} 1.0 & 0.0 & 0.0 \\ 0.0 & 1.0 & 0.0 \\ 0.0 & 0.0 & 1.0\\\end{bmatrix} \] + +\subsection{Commands for operations on matrices} +Table \ref{tbl:luamtxcmd} lists all commands for operations on matrices in the \verb|lualinalg| package. +\begin{longtable}{m{7cm}m{7cm}} +\toprule + \multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\ +\toprule +\multicolumn{2}{c}{Printing Matrices}\\ +\midrule +\begin{lstlisting} +\matrixPrint[type,truncate]{mtx} +\end{lstlisting} & Prints matrix. Accepts two \emph{optional} arguments: \verb|type| and \verb|truncate|. The \verb|type| may be one of the values \verb|pmatrix,bmatrix, vmatrix,Vmatrix|. +The default type is \verb|bmatrix|. The \verb|truncate| specifies the number of digits up to which matrix entries are to be truncated. The value of \verb|truncate| may be 0,1,2,\ldots.\\ +\midrule +\multicolumn{2}{c}{Some parameters of defined matrices} \\ +\midrule +\begin{lstlisting} +\matrixNumRows{matrix} +\end{lstlisting} & +Gives the number of rows in a matrix.\\ +\midrule +\begin{lstlisting} +\matrixNumCols{matrix} +\end{lstlisting}& +Gives the number of columns in a matrix.\\ +\midrule +\begin{lstlisting} +\matrixGetElement{matrix}{i}{j} +\end{lstlisting} +& +Gives an entry of matrix in the \(i^{th} \) row and the \(j^{th} \) column. \\ +\midrule +\multicolumn{2}{c}{Algebraic operations on matrices} \\ +\midrule + \begin{lstlisting} +\matrixAdd{matrix}{m1}{m2} +\end{lstlisting}& +Defines a new matrix as the addition of matrices m1 and m2. The second matrix may have more rows and\textbackslash or columns.\\ +\midrule + \begin{lstlisting} +\matrixSub{matrix}{m1}{m2} +\end{lstlisting}& +Defines a new matrix as the subtraction of matrices m1 and m2. The second matrix may have more rows and\textbackslash or columns.\\ +\midrule + \begin{lstlisting} +\matrixMulNum{matrix}{number}{m1} +\end{lstlisting}& +Defines a new matrix obtained by multiplying each entry of matrix m1 by s real or complex number. \\ +\midrule +\begin{lstlisting} +\matrixMul{matrix}{m1}{m2} +\end{lstlisting}& +Defines a new matrix obtained by multiplying matrix m1 by matrix m2. The number of rows in matrix m2 must equal the number of columns in matrix m1.\\ +\midrule + \begin{lstlisting} +\matrixPow{matrix}{m1}{power} +\end{lstlisting}& +Defines a new matrix obtained by taking the \(i^{th}\) power of matrix m11 (multiplying matrix1 \(i\) times with itself). \\ +\midrule + \begin{lstlisting} +\matrixInvert{matrix}{matrix1} +\end{lstlisting}& +Defines a new matrix obtained by taking the inverse of matrix1. It throws an error if matrix is not invertible. \\ +\midrule +\begin{lstlisting} +\matrixTrace{matrix} +\end{lstlisting}& +Gives the trace (sum of diagonal entries) of a square matrix. It throws an error if the matrix is not square. \\ +\midrule + +\begin{lstlisting} +\matrixConjugate{matrix}{m1} +\end{lstlisting}& +Defines a new matrix obtained by taking the complex conjugate of each entry of matrix m1. \\ +\midrule + \begin{lstlisting} +\matrixConjugateT{matrix}{m1} +\end{lstlisting}& +Defines a new matrix obtained by taking the transpose of matrix m1 and then the complex conjugate of each matrix entry. \\ +\midrule +\begin{lstlisting} +\matrixNormOne{matrix} +\end{lstlisting}& +Calculates the norm1 of a matrix. For matrix \(A\) of size \(m \times n\), it is given by +\[ \|A\|_{1}=\max _{1 \leqslant j \leqslant n} \sum_{i=1}^{m}\left|a_{i j}\right| \] \\ +\midrule +\begin{lstlisting} +\matrixNormInfty{matrix} +\end{lstlisting}& +Calculates the infinity norm of a matrix. For matrix \(A\) of size \(m \times n\), it is given by +\[ \|A\|_{\infty}=\max _{1 \leqslant i \leqslant m} \sum_{j=1}^{n}\left|a_{i j}\right| \] \\ +\midrule +\begin{lstlisting} +\matrixNormMax{matrix} +\end{lstlisting}& +Calculates the max norm of a matrix. For matrix \(A\) of size \(m \times n\), it is given by +\[ \|A\|_{\max }=\max _{i,j}\left|a_{i j}\right| \] \\ +\midrule + \begin{lstlisting} +\matrixNormF{matrix} +\end{lstlisting}& +Calculates the Frobenius norm of a matrix. For matrix \(A\) of size \(m \times n\), it is given by +\[\|A\|_{F}=\sqrt{\sum_{i=1}^{m} \sum_{j=1}^{n}\left|a_{i j}\right|^{2}} \] \\ +\midrule + \begin{lstlisting} +\matrixRank{matrix} +\end{lstlisting}& +Gives the rank of matrix \(m\). It also supports matrices of complex numbers. \\ +\midrule + \begin{lstlisting} +\matrixDet{matrix} +\end{lstlisting}& +Gives the determinant of matrix \(m\). It also supports matrices of complex numbers. \\ +\midrule + \begin{lstlisting} +\matrixTranspose{matrix}{m1} +\end{lstlisting}& +Defines a new matrix obtained by taking the transpose of matrix m1. \\ +\midrule + \begin{lstlisting} +\matrixSetElement{matrix}{i}{j}{val} +\end{lstlisting} +& +Set entry of a matrix in the \(i^{th} \) row and \(j^{th} \) column as \verb|val|. \\ +\midrule + \begin{lstlisting} +\matrixSubmatrix{sm}{m}{i}{j}{k}{l} +\end{lstlisting}& +Defines a new matrix sm obtained by taking a submatrix of matrix m. Here \(i,j\) denotes the start row and start column, and \(k,l\) denotes the end row and end column for obtaining the submatrix. \\ +\midrule + \begin{lstlisting} +\matrixConcatH{matrix}{m1}{m2} +\end{lstlisting}& +Defines a new matrix obtained by augmenting matrix m1 with matrix m2 horizontally. \\ +\midrule + \begin{lstlisting} +\matrixConcatV{matrix}{m1}{m2} +\end{lstlisting}& +Defines a new matrix obtained by augmenting matrix m1 with matrix m2 vertically. \\ +\midrule +\begin{lstlisting} +\matrixOp{matrix}{expression} +\end{lstlisting}& +Defines a new matrix obtained by evaluating an expression. The expression supports all standard operations such as \(+,*, \) \^ \ . \\ +\midrule +\begin{lstlisting} +\matrixCopy{matrix}{matrix1} +\end{lstlisting}& +Defines a new matrix obtained by copying values from matrix1. \\ +\midrule + \begin{lstlisting} +\matrixCreateRandom +{m}{i}{j}{k}{l} +\end{lstlisting}& +Creates a new matrix m with random numbers. Here \(i,j\) denotes the number of rows and columns, and \(k, l\) denotes the start and end integers between which random numbers are generated. \\ +\midrule +\multicolumn{2}{c}{Elementary row operations on matrices} \\ +\midrule + \begin{lstlisting} +\matrixSwapRows{mtx}{m1}{i}{j} +\end{lstlisting}& +Defines a new matrix mtx obtained by swapping the \(i^{th}\) and \(j^{th}\) rows of matrix m1. \\ +\midrule + \begin{lstlisting} +\matrixMulRow{matrix}{m}{i}{no} +\end{lstlisting}& +Defines a new matrix obtained by multiplying the \(i^{th}\) row of matrix1 by a real or complex number. \\ +\midrule +\begin{lstlisting} +\matrixMulAddRow{mtx}{m}{i}{no}{j} +\end{lstlisting}& +Defines a new matrix mtx obtained by multiplying the \(i^{th}\) row of matrix1 by a real or complex number and adding it to the \(j^{th}\) row. \\ +\midrule +\multicolumn{2}{c}{Elementary column operations on matrices} \\ +\midrule +\begin{lstlisting} +\matrixSwapCols{mtx}{m}{i}{j} +\end{lstlisting}& +Defines a new matrix mtx obtained by swapping the \(i^{th}\) and \(j^{th}\) columns of matrix m. \\ +\midrule +\begin{lstlisting} +\matrixMulCol{matrix}{m}{i}{no} +\end{lstlisting}& +Defines a new matrix obtained by multiplying the \(i^{th}\) column of matrix1 by a real or complex number. \\ +\midrule + \begin{lstlisting} +\matrixMulAddCol{mtx}{m}{i}{no}{j} +\end{lstlisting}& +Defines a new matrix mtx obtained by multiplying the \(i^{th}\) column of matrix1 by a real or complex number and adding it to the \(j^{th}\) column. \\ +\midrule +\multicolumn{2}{c}{Reduced row echelon form of matrix} \\ +\midrule + \begin{lstlisting} +\matrixRREF{matrix}{matrix1} +\end{lstlisting}& +Defines a new matrix obtained by taking the reduced row echelon form of matrix1. It supports matrices of complex numbers as well. \\ +\midrule +\begin{lstlisting} +\matrixRREFSteps[type,truncate] +{matrix} +\end{lstlisting}& +Obtains reduced row echelon form of matrix in a step-by-step manner. The command has two optional parameters \verb|type| and \verb|truncate|. It supports matrices with complex numbers as well. \verb|type| may be one of the values \verb|pmatrix,bmatrix, vmatrix,Vmatrix|. +The default type is \verb|bmatrix|. \verb|truncate| specifies number of digits up to which matrix entries are to be truncated. \verb|truncate| may be 0,1,2,\ldots. \\ +\midrule +\multicolumn{2}{c}{Gauss-Jordan Elimination} \\ +\midrule +\begin{lstlisting} +\matrixGaussJordan{matrix} +{m1}{m2} +\end{lstlisting}& +Defines new matrix obtained by performing Gauss-Jordan elimination on augmented matrix \(m1|m2\). \\ +\midrule +\begin{lstlisting} +\matrixGaussJordanSteps[type,truncate] +{matrix}{m1}{m2} +\end{lstlisting}& +Defines new matrix obtained by performing Gauss-Jordan elimination on augmented matrix \(m1|m2\) in a step-by-step manner. The command has two optional parameters \verb|type| and \verb|truncate|. \verb|type| may be one of the values \verb|pmatrix, bmatrix, vmatrix,| \verb |Vmatrix|. The default type is \verb|bmatrix|. \verb|truncate| specifies number of digits up to which matrix entries are to be truncated. \verb|truncate| may be 0,1,2,\ldots. \\ +\bottomrule \\ +\caption{Commands for operations on matrices} +\label{tbl:luamtxcmd} +\end{longtable} +\subsection{Illustrations of matrix operations} +The following commands define matrices \(m,n,\) and \(r\). +\begin{lstlisting} +\def\r{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}} +\def\s{{{1,2,3},{4,5,6},{7,8,10}}} +\def\t{{{1,2,3},{4,5,6},{7,8,9}}} +\def\u{{{1},{2},{3}}} + +\matrixNew{m}{\r} +\matrixNew{n}{\s} +\matrixNew{p}{\t} +\matrixNew{q}{\u} +\end{lstlisting} +Table \ref{tbl:illluamatrix} illustrates various operations on matrices \(m,n,p,\) and \(q\). +\begin{center} +\begin{longtable}{lc} +\toprule +Commands & Output Produced\\ +\toprule +\multicolumn{2}{c}{Printing matrices}\\ +\midrule +\begin{lstlisting} +\(m=\matrixPrint{\m}\) +\end{lstlisting} & +\(m=\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i\end{bmatrix}\) +\\ +\midrule +\begin{lstlisting} +\(m=\matrixPrint[type=pmatrix]{\m}\) +\end{lstlisting} & +\(m=\begin{pmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i\end{pmatrix}\) +\\ +\midrule +\multicolumn{2}{c}{Some parameters of defined matrices}\\ +\midrule +\begin{lstlisting} +\(No. or rows in matrix m += \matrixNumRows{m}\) +\end{lstlisting} & +No. or rows in matrix \(m = 3\)\\ +\midrule +\begin{lstlisting} +\(No. or columns in matrix m += \matrixNumCols{m}\) +\end{lstlisting} & +No. or columns in matrix \(m = 3\)\\ +\midrule +\begin{lstlisting} +\(Element of matrix m at (3,3) = + \matrixGetElement{m}{3}{3}\) +\end{lstlisting} & +\(9+3i\)\\ +\midrule +\multicolumn{2}{c}{Algebraic operations on matrices}\\ +\midrule +\begin{lstlisting} +\matrixAdd{m1}{m}{p} +\(m1 = \matrixPrint{m1}\) +\end{lstlisting} & +\(m1 = \begin{bmatrix} 2.0 & 4.0 & 6.0 \\ 8.0 & 10.0 & 12.0 \\ 14.0 & 16.0 & 18.0+3.0i\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixSub{m2}{m}{p} +\(m2 = \matrixPrint{m2}\) +\end{lstlisting} & +\(m2 = \begin{bmatrix} 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 3.0i \end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixMulNum{m3}{3}{m} +\(m3 = \matrixPrint{m3}\) +\end{lstlisting} & +\(m3 = \begin{bmatrix} 3.0 & 6.0 & 9.0 \\ 12.0 & 15.0 & 18.0 \\ 21.0 & 24.0 & 27.0+9.0i\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixMul{m4}{m}{p} +\(m4 = \matrixPrint{m4}\) +\end{lstlisting} & +\(m4 = \begin{bmatrix} 30.0 & 36.0 & 42.0 \\ 66.0 & 81.0 & 96.0 \\ 102.0+21.0i & 126.0+24.0i & 150.0+27.0i\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixPow{m5}{m}{2} +\(m5 = \matrixPrint{m5}\) +\end{lstlisting} & +\(m5 = \begin{bmatrix} 30.0 & 36.0 & 42.0+9.0i \\ 66.0 & 81.0 & 96.0+18.0i \\ 102.0+21.0i & 126.0+24.0i & 141.0+54.0i\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixInvert{m6}{m} +\(m6 = \matrixPrint[truncate=4]{m6}\) +\end{lstlisting} & +\(m6 = \begin{bmatrix} -1.6667-0.3333i & 0.6667+0.6667i & -0.3333i \\ 1.3333+0.6667i & -0.3333-1.3333i & 0.6667i \\ -0.3333i & 0.6667i & -0.3333i\end{bmatrix} +\)\\ +\midrule + +\begin{lstlisting} +Rank of matrix \(m =\matrixRank{m}\) + +\end{lstlisting} & +Rank of matrix \(m = 3\)\\ +\midrule +\begin{lstlisting} +Determinant of matrix \(m =\matrixDet{m}\) +\end{lstlisting} & +Determinant of matrix \(m = -9i\)\\ +\midrule +\begin{lstlisting} +\matrixTranspose{m7}{m} +\(m7 = \matrixPrint{m7}\) +\end{lstlisting} & +\(m7 = \begin{bmatrix}1.0 & 4.0 & 7.0 \\ 2.0 & 5.0 & 8.0 \\ 3.0 & 6.0 & 9.0+3.0i\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixSetElement{n}{3}{3}{300} +\(n= \matrixPrint{n}\) +\end{lstlisting} & +\(n = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 300.0\end{bmatrix} +\)\\ +\midrule + +\begin{lstlisting} +\matrixSubmatrix{m8}{m}{1}{2}{2}{3} +\(m8 = \matrixPrint{m8}\) +\end{lstlisting} & +\(m8 = \begin{bmatrix} 2.0 & 3.0 \\ 5.0 & 6.0\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixConcatH{m9}{m}{q} +\(m9= \matrixPrint{m9}\) +\end{lstlisting} & +\(m9 = \begin{bmatrix}1.0 & 2.0 & 3.0 & 1.0 \\ 4.0 & 5.0 & 6.0 & 2.0 \\ 7.0 & 8.0 & 9.0+3.0i & 3.0\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixConcatV{m10}{m}{n} +\(m10= \matrixPrint{m10}\) +\end{lstlisting} & +\(m10= \begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i \\ 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 300.0\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixOp{m11}{m*m+2*m} +\(\matrixPrint[truncate=4]{m11}\) +\end{lstlisting} & +\(m11 = \begin{bmatrix} 32.0 & 40.0 & 48.0+9.0i \\ 74.0 & 91.0 & 108.0+18.0i \\ 116.0+21.0i & 142.0+24.0i & 159.0+60.0i\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixCopy{m12}{m} +\(m12 = \matrixPrint{m12}\) +\end{lstlisting} & +\(m12 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i\end{bmatrix} +\)\\ + +\midrule +\begin{lstlisting} +trace of matrix \( m = \matrixTrace{m}\) +\end{lstlisting} & +trace of matrix \( m = 15+3i\) \\ + +\midrule +\begin{lstlisting} +\matrixConjugate{mc}{m} +\(mc = \matrixPrint{mc}\) +\end{lstlisting} & +\(mc = \begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0-3.0i\end{bmatrix} +\)\\ +\midrule + +\begin{lstlisting} +\matrixConjugateT{mct}{m} +\(mct = \matrixPrint{mct}\) +\end{lstlisting} & +\(mct = \begin{bmatrix} 1.0 & 4.0 & 7.0 \\ 2.0 & 5.0 & 8.0 \\ 3.0 & 6.0 & 9.0-3.0i\end{bmatrix} +\)\\ +\midrule + +\begin{lstlisting} + \(\matrixNormOne{m}\) +\end{lstlisting} & + \(18.486832980505\) \\ + +\midrule +\begin{lstlisting} + \(\matrixNormInfty{m}\) +\end{lstlisting} & + \(24.486832980505\) \\ + +\midrule +\begin{lstlisting} + \(\matrixNormMax{m}\) +\end{lstlisting} & + \(9.4868329805051\) \\ + +\midrule +\begin{lstlisting} + \(\matrixNormF{m}\) +\end{lstlisting} & +\( 17.146428199482\) \\ + +\midrule +\multicolumn{2}{c}{Elementary row operations on matrices}\\ +\midrule +\begin{lstlisting} +\matrixSwapRows{m13}{m}{2}{3} +\(m13 = \matrixPrint{m13}\) +\end{lstlisting} & +\(m13 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 7.0 & 8.0 & 9.0+3.0i \\ 4.0 & 5.0 & 6.0\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixMulRow{m14}{m}{3}{300} +\(m14 = \matrixPrint{m14}\) +\end{lstlisting} & +\(m14 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 2100.0 & 2400.0 & 2700.0+900.0i \end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixMulAddRow{m15}{m}{2}{10}{3} +\(m15 = \matrixPrint{m15}\) +\end{lstlisting} & +\(m15 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 47.0 & 58.0 & 69.0+3.0i\end{bmatrix} +\)\\ +\midrule +\multicolumn{2}{c}{Elementary column operations on matrices}\\ +\midrule +\begin{lstlisting} +\matrixSwapCols{m16}{m}{2}{3} +\(m16 = \matrixPrint{m16}\) +\end{lstlisting} & +\(m16 = \begin{bmatrix}1.0 & 3.0 & 2.0 \\ 4.0 & 6.0 & 5.0 \\ 7.0 & 9.0+3.0i & 8.0\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixMulCol{m17}{m}{3}{300} +\(m17 = \matrixPrint{m17}\) +\end{lstlisting} & +\(m17 = \begin{bmatrix} 1.0 & 2.0 & 900.0 \\ 4.0 & 5.0 & 1800.0 \\ 7.0 & 8.0 & 2700.0+900.0i \end{bmatrix} +\)\\ +\midrule + +\begin{lstlisting} +\matrixMulAddCol{m18}{m}{2}{10}{3} +\(m18 = \matrixPrint{m18}\) +\end{lstlisting} & +\(m18 = \begin{bmatrix}1.0 & 2.0 & 23.0 \\ 4.0 & 5.0 & 56.0 \\ 7.0 & 8.0 & 89.0+3.0i\end{bmatrix} +\)\\ +\midrule + +\multicolumn{2}{c}{Reduced row echelon form of a matrix}\\ +\midrule +\begin{lstlisting} +\matrixRREF{m19}{p} +\(m19 = \matrixPrint{m19}\) +\end{lstlisting} & +\(m19 = \begin{bmatrix}1.0 & 0.0 & -1.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & 0.0 & 0.0\end{bmatrix} +\)\\ +\midrule +\begin{lstlisting} +\matrixRREF{m20}{m} +\(m20 = \matrixPrint{m20}\) +\end{lstlisting} & +\(m20 = \begin{bmatrix} 1.0 & 0.0 & 0.0 \\ 0.0 & 1.0 & 0.0 \\ 0.0 & 0.0 & 1.0\end{bmatrix} +\)\\ +\bottomrule \\ +\caption{Illustration of commands for operations on matrices} +\label{tbl:illluamatrix} +\end{longtable} +\end{center} + +The package has command \verb|\matrixRREFSteps| to produce step-by-step computation of reduced row echelon form of a matrix. The command \verb|\matrixRREFSteps{p}| outputs the following. +\begin{framed}Step 1:Multiply row 1 by 4.0 and subtract it from row 2.$$\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 0.0 & -3.0 & -6.0 \\ 7.0 & 8.0 & 9.0 \\ \end{bmatrix} $$Step 2:Multiply row 1 by 7.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 0.0 & -3.0 & -6.0 \\ 0.0 & -6.0 & -12.0 \\ \end{bmatrix} $$Step 3:Divide row 2 by -3.0.$$\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & -6.0 & -12.0 \\ \end{bmatrix} $$Step 4:Multiply row 2 by 2.0 and subtract it from row 1.$$\begin{bmatrix} 1.0 & 0.0 & -1.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & -6.0 & -12.0 \\ \end{bmatrix} $$Step 5:Multiply row 2 by -6.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 0.0 & -1.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & 0.0 & 0.0 \\ \end{bmatrix} $$ +\end{framed} + +The command \verb|\matrixGaussJordan| is used to obtain Gauss-Jordan elimination of an augmented matrix. + +\begin{lstlisting} +\def\a{{{1,1,1},{2,-1,-1},{1,-1,1}}} +\def\b{{{3},{3},{9}}} +\matrixNew{S}{\a} +\matrixNew{T}{\b} +\matrixConcatH{W}{S}{T} +$$W = \matrixPrint{W}$$ +\matrixGaussJordan{U}{S}{T} +$$U = \matrixPrint{U}$$ +\end{lstlisting} + +The above code produces the following output. +\begin{framed} +$$W =\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 2.0 & -1.0 & -1.0 & 3.0 \\ 1.0 & -1.0 & 1.0 & 9.0 \\ \end{bmatrix} $$ +$$U = \begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 0.0 & -3.0 \\ 0.0 & 0.0 & 1.0 & 4.0 \\ \end{bmatrix}$$ +\end{framed} + +The package also has a command \verb|\matrixGaussJordanSteps| to produce step-by-step computation of Gauss-Jordan elimination of an augmented matrix. The command \verb|\matrixGaussJordanSteps{S}{T}| produces the following output. + +\begin{framed} +$$W =\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 2.0 & -1.0 & -1.0 & 3.0 \\ 1.0 & -1.0 & 1.0 & 9.0 \\ \end{bmatrix} $$ +Step 1:Multiply row 1 by 2.0 and subtract it from row 2.$$\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 0.0 & -3.0 & -3.0 & -3.0 \\ 1.0 & -1.0 & 1.0 & 9.0 \\ \end{bmatrix} $$Step 2:Multiply row 1 by 1.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 0.0 & -3.0 & -3.0 & -3.0 \\ 0.0 & -2.0 & 0.0 & 6.0 \\ \end{bmatrix} $$Step 3:Divide row 2 by -3.0.$$\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & -2.0 & 0.0 & 6.0 \\ \end{bmatrix} $$Step 4:Multiply row 2 by 1.0 and subtract it from row 1.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & -2.0 & 0.0 & 6.0 \\ \end{bmatrix} $$Step 5:Multiply row 2 by -2.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & 0.0 & 2.0 & 8.0 \\ \end{bmatrix} $$Step 6:Divide row 3 by 2.0.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & 0.0 & 1.0 & 4.0 \\ \end{bmatrix} $$Step 7:Multiply row 3 by 1.0 and subtract it from row 2.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 0.0 & -3.0 \\ 0.0 & 0.0 & 1.0 & 4.0 \\ \end{bmatrix} $$ +\end{framed} + +\section{Customized usage}\label{customuse} +The commands available in the package can be used for performing further operations on vectors and matrices. The command \verb|\vectorAdd| can be extended to add more than two vectors. The latex document (listing \ref{code:custluavec}) provides some instances of such usage. +\begin{lstlisting}[label={code:custluavec}, caption={Customized usage of the lualinalg package}] +\documentclass{article} +\usepackage{lualinalg} +\begin{document} +\begin{luacode} +function sumcoordinates(v1) +local sum = 0 +for i = 1,#v1 do + sum = sum + v1[i] + end +return sum +end + +function vector.addmulti(...) + p=table.pack(...) + s=vector(p[1]) + for i=2,#p do +s=vector.add(s,vector(p[i])) +end + return s +end +\end{luacode} +\vectorNew{v}{{1,2,complex('3+3i')}} +The sum of coordinates of vector + \(v = \directlua{tex.sprint(tostring( sumcoordinates(v)))}\). + +\newcommand\vectorAddmulti[2]{% + \directlua{% + vectors['#1'] = vector.addmulti(#2) + }% +} + +\vectorNew{w}{{3,6,complex('6+6i')}} +\vectorNew{x}{{9,12,complex('12+12i')}} +\vectorAddmulti{y}{v,w,x} +The sum of vectors \(v,w \text{ and } x =\left( \vectorPrint{y} \right)\). +\end{document} +\end{lstlisting} + +The latex document (listing \ref{code:custluavec}) outputs the following on compilation. +\begin{framed} +The sum of coordinates of vector \(v = 6 + 3i\). + +The sum of vectors \(v,w \text{ and } x = \left(13.0, 20.0, 21.0 + 21.0i \right) \). +\end{framed} + + +The command \verb|\matrixAdd| can be extended to add more than two matrices. The latex document (listing \ref{code:custluamtx}) provides some instances of such usage. + +\begin{lstlisting}[label={code:custluamtx}, caption={Customized usage of the lualinalg package}] +\documentclass{article} +\usepackage{lualinalg} +\begin{document} +\begin{luacode} +function squareDiagEntries(m1) + if #m1 ~= #m1[1] then error( "matrix not square") end + local sum = 0 +for i = 1,#m1 do + for j = 1,#m1[1] do + if i == j then sum = sum + (m1[i][j])^2 end + end + end +return sum +end + +function matrix.addmulti(...) + p=table.pack(...) + s=matrix(p[1]) + for i=2,#p do +s=matrix.add(s,matrix(p[i])) +end + return s +end +\end{luacode} + +\def\r{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}} +\matrixNew{m}{\r} +The sum of squares of diagonal entries of matrix + \(m = \directlua{tex.sprint(tostring(squareDiagEntries(m)))}\). + +\def\s{{{1,2,3},{4,5,complex('6+6i')}}} +\def\t{{{10,20,30},{40,50,complex('60+60i')}}} +\def\u{{{100,200,300},{400,500,complex('600+600i')}}} +\matrixNew{m1}{\s} +\matrixNew{m2}{\t} +\matrixNew{m3}{\u} +\newcommand\matrixAddmulti[2]{% + \directlua{% + matrices['#1'] = matrix.addmulti(#2) + }% +} +\matrixAddmulti{m4}{m1,m2,m3} +The sum of matrices \(m1,m2 \text{ and } m3 = \matrixPrint{m4}\). +\end{document} +\end{lstlisting} + +The latex document (listing \ref{code:custluamtx}) outputs the following on compilation. +\begin{framed} +The sum of squares of diagonal entries of matrix \(m = 98.0 + 54i\). + +The sum of matrices \(m1,m2 \text{ and } m3 =\begin{bmatrix} 111.0 & 222.0 & 333.0 \\ 444.0 & 555.0 & 666.0+666.0i \end{bmatrix} \). +\end{framed} + +\section{Known issues and limitations} +\begin{itemize} +\item The package supports small and big numbers. They can be input in the usual scientific notation. The math library in Lua defines constants with the maximum \verb|math.maxinteger| and the minimum \verb|math.mininteger| values for an integer. The result wraps around when there is a computational operation on integers that would result in a value smaller than the \verb|mininteger| or larger than the \verb|maxinteger|. It means that the computed result is the only number between the \verb|miniinteger| and \verb|maxinteger|. + +\item The package currently supports only numerical computations. The table in a Lua is a data type that implements an associative array. This feature is used in packages to define and store vectors and matrices. This approach is close to object-oriented programming. It will allow easy conversion of algorithms in packages for symbolic computations. Future package updates will consider algorithm conversions to support symbolic calculations. + +\item The error handling mechanism in the tool is not robust. There are some custom errors included in the package. However the package mostly depends on error handling mechanism of Lua. The error handling can be strengthened in future updates of the package. + +\end{itemize} +\end{document}
\ No newline at end of file diff --git a/macros/optex/README b/macros/optex/README index f6a86e51d2..36c2c98bb1 100644 --- a/macros/optex/README +++ b/macros/optex/README @@ -22,6 +22,12 @@ doc/ ... PDF version of the OpTeX documentation and sources. History: +<1.10> Feb 2022: + key-values improved: \iskv, \kvx, \nokvx introduced. + unimath-codes: control sequences are macros, no \chardef. + \bp, \expr: optional syntax for setting the number of digits after decimal point. + \isnextchar is expandable. + math.opm: various improvements. <1.09> Dec 2022: New math.opm package: doing math more comfortable. The math.opm package can be a package template for macro writers. diff --git a/macros/optex/base/alloc.opm b/macros/optex/base/alloc.opm index d4f823fec4..fae88d286e 100644 --- a/macros/optex/base/alloc.opm +++ b/macros/optex/base/alloc.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \newdimen {Allocators for registers <2022-06-10>} % preloaded in format +\_codedecl \newdimen {Allocators for registers <2023-02-03>} % preloaded in format \_doc ----------------------------- The limits are set first. @@ -46,9 +46,10 @@ \_errmessage{No room for a new \_ea\_string\_csname #2\_endcsname}% \_else \_global#3#1=\_cs{_#2alloc}% - \_wlog{\_string#1=\_ea\_string\_csname #2\_endcsname\_the\_cs{_#2alloc}}% + \_wloga{\_string#1=\_ea\_string\_csname #2\_endcsname\_the\_cs{_#2alloc}}% \_fi } +\_let\_wloga=\_wlog % you can suppress the logging by \_let\_wloga=\_ignoreit \_doc ----------------------------- The allocation macros @@ -177,6 +178,7 @@ the array-like declarator of counters. \_endinput +2023-02-03 \_wloga introduced 2022-06-10 \_famalloc set to 42 (answer to the biggest fundamental question) 2022-03-07 \_noattr allocated 2022-02-19 \_newlanguage introduced diff --git a/macros/optex/base/basic-macros.opm b/macros/optex/base/basic-macros.opm index ae5c833140..9227505678 100644 --- a/macros/optex/base/basic-macros.opm +++ b/macros/optex/base/basic-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \sdef {Basic macros for OpTeX <2022-11-22>} % preloaded in format +\_codedecl \sdef {Basic macros for OpTeX <2023-01-22>} % preloaded in format \_doc ------------------------------ \`\bgroup`, \`\egroup`, \`\empty`, \`\space`, and \`\null` @@ -73,7 +73,7 @@ \_cod ------------------------------ \_def \_cs #1{\_csname#1\_endcsname} -\_def \_trycs#1#2{\_ifcsname #1\_endcsname \_csname #1\_ea\_endcsname \_else #2\_fi} +\_def \_trycs#1#2{\_ifcsname #1\_endcsname \_csname #1\_ea\_endcsname \_else \_afterfi{#2}\_fi} \_public \cs \trycs ; \_doc ------------------------------ @@ -142,6 +142,7 @@ \_endcode % ------------------------------------- +2023-01-22: \trycs: afterfi used for second parameter 2022-11-22: \_banner definition moved here 2022-11-18: \ahead introduced 2022-10-29: \_fin introduced diff --git a/macros/optex/base/doc.opm b/macros/optex/base/doc.opm index dc5d037e72..fb96d35007 100644 --- a/macros/optex/base/doc.opm +++ b/macros/optex/base/doc.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \printdoc {Macros for documentation printing <2022-11-21>} % loaded on demand by \load[doc] +\_codedecl \printdoc {Macros for documentation printing <2022-12-11>} % loaded on demand by \load[doc] \_doc ----------------------------- General decalarations. @@ -204,7 +204,7 @@ \_doc ----------------------------- If this macro is loaded by \^`\load` then we need to initialize - catcodes using the `\_afteroad` macro. + catcodes using the `\_afterload` macro. \_cod ----------------------------- \_def\_afterload{\_catcode`\<=13 \_catcode`\`=13 @@ -229,26 +229,32 @@ Link to user documentation point: \code{\\~`\\foo}. \_cod ----------------------------- +\_def\_docrefcodes{\_catcode`\.=11\_relax} + \_verbchar` -\_def\`#1`{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% - \_ifcsname cs:\_tmp\_endcsname\_else \_dest[cs:\_tmp]\_fi +\_def\`{\_bgroup \_docrefcodes \_mainpoint} +\_def\_mainpoint #1`{\_egroup\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% + \_ifcsname cs:\_tmp\_endcsname \_moremainpoints \_else \_dest[cs:\_tmp]\_fi \_sxdef{cs:\_tmp}{}% \_hbox{\_ifcsname cs:^\_tmp\_endcsname \_link[cs:^\_tmp]{\mlinkcolor}{\_tt\_csstring\\\_tmp}\_else {\_tt\mlinkcolor\_csstring\\\_tmp}\_fi}% } -\_def\^`#1{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% +\_def\^`{\_bgroup \_docrefcodes \_docpoint} +\_def\_docpoint #1{\_egroup\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% \_hbox{\_ifcsname cs:^\_tmp\_endcsname \_else \_dest[cs:^\_tmp]\_sxdef{cs:^\_tmp}{}\_fi \_link[cs:\_tmp]{\ulinkcolor}{\_tt\_string#1}}% \_futurelet\_next\_cslinkA } \_def\_cslinkA{\_ifx\_next`\_ea\_ignoreit \_else \_ea\_ea\_ea`\_ea\_string\_fi} -\_def\~`#1{\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% +\_def\~`{\_bgroup \_docrefcodes \_doctpoint} +\_def\_doctpoint #1{\_egroup\_leavevmode\_edef\_tmp{\_csstring#1}\_iindex{\_tmp}% \_hbox{\_link[cs:^\_tmp]{\ulinkcolor}{\_tt\_string#1}}% \_futurelet\_next\_cslinkA } +\_def\_moremainpoints{\_opwarning{Second main documentation point \_bslash\_tmp}} \_doc ----------------------------- The \`\fw` macro for forward links to user documentation point (given later) @@ -357,6 +363,8 @@ have the same meaning: `\optexdoclink` in this example. And \endinput +2022-12-11 \_opwaning "Second main documentation point" introduced. +2022-12-11 \_docrefcodes added (bug due to 2022-11-13 fixed). 2022-11-21 magenta color for internal links instead green. 2022-11-13 \catcode`.=11: only local settings 2022-07-01 \_printii improved, colors declaration part added. diff --git a/macros/optex/base/f-heros.opm b/macros/optex/base/f-heros.opm index 2531573ca4..d749553882 100644 --- a/macros/optex/base/f-heros.opm +++ b/macros/optex/base/f-heros.opm @@ -193,12 +193,16 @@ so the first font from the new family is loaded and it is ready to use it. \seccc Name conventions -Create font modifiers, new variants, and the `\<Familyselector>` only as public, i.e. -in user namespace without `_` prefix. We assume that if a user re-defines them then he/she needs +Create font modifiers, new variants, and the `\<Familyselector>` only in +public namespace without `_` prefix. We assume that if a user re-defines them then he/she needs not them, so we have no problems. If the user's definition was done before loading the font family file then it is re-defined and \OpTeX/ warns about it. See the end of section~\ref[fontcommands]. +If you need to use an internal control sequence declared in your fontfile, +use the reserved name space with names starting with two `_` followed by family +indentifier or by `vf` if it relates to variable fonts. + The name of `\<Familyselector>` should begin with an uppercase letter. Please, look at diff --git a/macros/optex/base/fonts-resize.opm b/macros/optex/base/fonts-resize.opm index 34885d44bd..e76596611b 100644 --- a/macros/optex/base/fonts-resize.opm +++ b/macros/optex/base/fonts-resize.opm @@ -107,7 +107,7 @@ The \`\_regtfm` `<font id> <optical size data>` registers optical sizes data directly by the font file names. This can be used for `tfm` files or OpenType files without - various font features. See also \`\_regoptsizes` in section~\ref[optsizes]. + various font features. See also \^`\_regoptsizes` in section~\ref[optsizes]. The `\_regtfm` command saves the <optical size data> concerned to the `<font id>`. The `<optical size data>` is in the form as shown below in the code where `\_regtfm` is used. diff --git a/macros/optex/base/fonts-select.opm b/macros/optex/base/fonts-select.opm index 7e00c9baea..6b10f75aff 100644 --- a/macros/optex/base/fonts-select.opm +++ b/macros/optex/base/fonts-select.opm @@ -733,10 +733,10 @@ Compare ex-height of Termes \rmsans with Heros \rm and Termes. \endtt The variant selectors (declared by \~`\famvardef`) or font -modifiers (declared by \~`\moddef`) are (typically) control sequences in user name -space (`\mf`, `\caps`). They are most often declared in font family files and +modifiers (declared by \~`\moddef`) are (typically) control sequences in the public +namespace (`\mf`, `\caps`). They are most often declared in font family files and they are loaded by \^`\fontfam`. A conflict with such names in -user namespace can be here. For example: if `\mf` is defined by a user and then +the public namespace can be here. For example: if `\mf` is defined by a user and then `\fontfam[Roboto]` is used then `\famvardef\mf` is performed for Roboto family and the original meaning of `\mf` is lost. But \OpTeX/ prints warning about it. There are two cases: diff --git a/macros/optex/base/hisyntax-c.opm b/macros/optex/base/hisyntax-c.opm index 3c1f228f88..d0a4217b31 100644 --- a/macros/optex/base/hisyntax-c.opm +++ b/macros/optex/base/hisyntax-c.opm @@ -52,7 +52,7 @@ User can re-declare his/her own colors by `\hicolors` which has precedence before `\_hicolors<name>`. The public variants can be declared if you want to give these token lists to -the user namespace. But it is not explicitly needed. +the public namespace. But it is not explicitly needed. All settings must be global here because the file is typically read inside a group and we need not read it repeatedly before each code chunk diff --git a/macros/optex/base/if-macros.opm b/macros/optex/base/if-macros.opm index 9113b5f8be..148c855941 100644 --- a/macros/optex/base/if-macros.opm +++ b/macros/optex/base/if-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \newif {Special if-macros, is-macros and loops <2022-12-02>} % preloaded in format +\_codedecl \newif {Special if-macros, is-macros and loops <2023-01-16>} % preloaded in format \_doc ---------------------------- \secc Classical \code{\\newif} @@ -64,6 +64,7 @@ \_def \_iterate {\_body \_ea \_iterate \_fi} \_doc ----------------------------- + {\_let\_moremainpoints=\_relax \`\foreach` `<list>`\`\do` `{<what>}` repeats `<what>` for each element of the `<list>`. The `<what>` can include `#1` which is substituted by each @@ -82,7 +83,7 @@ Recommendation: it is better to use private variants of \`\_foreach`. When the user writes `\input tikz` then `\foreach` macro is redefined in each TikZ environment. - The private variants use \`\_do` separator instead `\do` separator. + The private variants use \`\_do` separator instead `\do` separator.} \_cod ----------------------------- \_newcount\_frnum % the numeric variable used in \fornum @@ -101,6 +102,7 @@ \_afterfi{\_foreachA{#1}{##1}}\_else\_afterfi{\_foreachA{#1}{#2}}\_fi} \_doc ----------------------------- + {\_let\_moremainpoints=\_relax \`\fornum` `<from>..<to>` \`\do` `{<what>}` or \`\fornumstep` `<num>: <from>..<to>` \`\do` `{<what>}` repeats `<what>` for each number from `<from>` to `<to>` (with step `<num>` @@ -110,7 +112,7 @@ The test in the \`\_fornumB` says: if (<to> $\string<$ <current number> AND <step> is positive) or if (<to> $>$ <current number> AND <step> is negative) then close loop by `\_getforstack`. Sorry, the condition is - writen by somewhat cryptoid \TeX/ language. + writen by somewhat cryptoid \TeX/ language.} \_cod ----------------------------- \_def\_fornum#1..#2\_do{\_fornumstep 1:#1..#2\_do} @@ -292,16 +294,17 @@ \_public \isfont ; \_doc ---------------------------- - The last macro \`\isnextchar` `<char>{<codeA>}{<codeB>}` + The macro \`\isnextchar` `<char>{<codeA>}{<codeB>}` has a different syntax than all other is-macros. It executes `<codeA>` if next character is equal to <char>. - Else the `<codeB>` is executed. The macro is not expandable. + Else the `<codeB>` is executed. The macro is expandable. \_cod ---------------------------- -\_long\_def\_isnextchar#1#2#3{\_begingroup\_toks0={\_endgroup#2}\_toks1={\_endgroup#3}% - \_let\_tmp= #1\_futurelet\_next\_isnextcharA +\_long\_def\_isnextchar#1#2#3{\_immediateassignment + \_def\_isnextcharA{\_isnextcharB{#1}{#2}{#3}}% + \_immediateassignment\_futurelet \_next \_isnextcharA } -\_def\_isnextcharA{\_the\_toks\_ifx\_tmp\_next0\_else1\_fi\_space} +\_long\_def\_isnextcharB#1{\_ifx\_next#1\_ea\_ignoresecond\_else\_ea\_usesecond\_fi} \_public \isnextchar ; @@ -359,6 +362,7 @@ \_endcode +2023-01-16 \isnextchar created expandable. 2022-12-02 \xcasesof: its first parameter is \long too. 2022-11-29 renamed to \casesof, \xcasesof. 2022-11-26 \casesby, \casesbyif introduced. diff --git a/macros/optex/base/keyval.opm b/macros/optex/base/keyval.opm index 7d089ce6b1..21e6f9acf3 100644 --- a/macros/optex/base/keyval.opm +++ b/macros/optex/base/keyval.opm @@ -1,26 +1,39 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \readkv {Key-value dictionaries <2020-12-21>} % preloaded in format +\_codedecl \readkv {Key-value dictionaries <2023-01-14>} % preloaded in format \_doc ---------------------------- - {\bf Implementation.} + {\bf Implementation.}\nl The \`\readkv``<list>` expands its parameter and does replace-strings in order to - remove spaces around equal signs and after commas. Double commas are - removed. Then \`\_kvscan` reads the parameters list finished by the double - comma and saves values to `\_kv:<key>` macros.\nl - The \`\kv``{<key>}` expands the `\_kv:<key>` macro. If this macro isn't - defined then \`\_kvunknown` is processed. You can re-define it if you want. + remove spaces around equal signs and after commas. + Then \`\_kvscan` reads the parameters list finished by `,\_fin,` + and saves values to `\_kv:<dict>:<key>` macros. + The `\_kvx:<dict>:<key>` is processed (if it is defined) with parameter + <value> after it.\nl + The \`\kvx``{<key>}{<code>}` defines the `\_kvx:<dict>:<key>#1` macro + and \`\nokvx``{<code>}` defines the `\_nokvx:<dict>:<key>` macro.\nl + The \`\kv``{<key>}` expands the `\_kv:<dict>:<key>` macro. If this macro isn't + defined then \`\_kvunknown` is processed. You can re-define it if you want.\nl + The \`\iskv``{<key>}\iftrue` (or `\iffalse`) is the test, + if the `<key>` is defined in current <dict>. \_cod ---------------------------- \_def\_readkv#1{\_ea\_def\_ea\_tmpb\_ea{#1}% - \_replstring\_tmpb{= }{=}\_replstring\_tmpb{ =}{=}% - \_replstring\_tmpb{, }{,}\_replstring\_tmpb{,,}{,}% - \_ea \_kvscan \_tmpb,,=,} -\_def\_kvscan #1#2=#3,{\_ifx#1,\_else \_sdef{_kv:#1#2}{#3}\_ea\_kvscan\_fi} -\_def\_kv#1{\_trycs{_kv:#1}{\_kvunknown}} + \_replstring\_tmpb{= }{=}\_replstring\_tmpb{ =}{=}\_replstring\_tmpb{, }{,}% + \_ea \_kvscan\_tmpb,\_fin,} +\_def\_kvscan#1,{\_ifx\_fin#1\_empty\_ea\_ignoreit \_else\_ea\_useit \_fi + {\_kvsd #1==\_fin \_kvscan}} +\_def\_kvsd#1=#2=#3\_fin{\_sdef{\_kvcs#1}{#2}% + \_trycs{_kvx:\_the\_kvdict:#1}% + {\_trycs{_nokvx:\_the\_kvdict}{\_ea\_ignoreit}{#1}\_ea\_ignoreit}{#2}} +\_def\_kvx#1#2{\_sdef{_kvx:\_the\_kvdict:#1}##1{#2}} +\_def\_nokvx#1{\_sdef{_nokvx:\_the\_kvdict}##1\_ea\_ignoreit\_fi##2{\_fi#1}} +\_def\_kv#1{\_trycs{\_kvcs#1}{\_kvunknown}} +\_def\_iskv#1#2{#2\_else\_ea\_unless\_fi \_ifcsname\_kvcs#1\_endcsname} +\_def\_kvcs{_kv:\_the\_kvdict:} \_def\_kvunknown{???} -\public \readkv \kv ; +\public \readkv \kvx \nokvx \kv \iskv ; \_endcode @@ -43,7 +56,7 @@ or simply `\myframe {text3}`. You can define `\myframe` as follows: \begtt \def\myframedefaults{% defaults: frame-color=\Black, % color of frame rules - text-color=\Black, % color ot text inside the frame + text-color=\Black, % color of text inside the frame rule-width=0.4pt, % width of rules used in the frame margins=2pt, % space between text inside and rules. } @@ -64,18 +77,54 @@ The last setting wins. Third: the values can be used by the expandable \^`\kv{<key>}` macro. The \^`\kv{<key>}` returns `???` if such key is not declared. -You can use keys without values in the parameters list too, but with -additional care. For example, suppose `draft` option without parameter. -If a user writes `\myframe [..., draft, ...]{text}` then `\myframe` should behave differently. -We have to add `DRAFTv=0,` in `\myframedefault` macro. -Moreover, `\myframe` macro must include preprocessing of `\myframedefault` using -\^`\replstring` which replaces the occurrence of `draft` by `DRAFTv=1`. +You can use keys without values in the parameters list too. +Then you can ask if the key is declared by \^`\iskv``{<key>}\iftrue` +or the key is undeclared by \^`\iskv``{<key>}\iffalse`. +For example, you write to your documentation of your code that +user can set the `draft` option without the value. Then you can do \begtt \optdef\myframe [] #1{... - \ea\addto\ea\myframedefaults\ea{\the\opt}% - \replstring\myframedefaults{draft}{DRAFTv=1}% - \readkv\myframedefaults - ... - \ifnum\kv{DRAFTv}=1 draft mode\else normal mode\fi + \readkv\myframedefaults \readkv{\the\opt}% + \iskv{draft}\iftrue ...draft mode... \else ...final mode... \fi + ...} +\endtt +Maybe, you want to allow not ony `draft` option but `final` option (which is +opposite to `draft`) too and you want to apply the result from the last given +option. Then `\iskv` doesn't work because you can only check if both options +are declared but you don't know what one is given as last. But you can +use \^`\kvx``{<key>}{<code>}` to declare <code> which is processed +immediately when the `<key>` is processed by `\readkv`. For example +\begtt +\newcount\mydraftmode +\kvx{draft}{\mydraftmode=1 } +\kvx{final}{\mydraftmode=0 } +\optdef\myframe [] #1{... + \readkv\myframedefaults \readkv{\the\opt}% + \ifnum\mydraftmode=1 ...draft mode... \else ...final mode... \fi ...} \endtt +The syntax of \^`\kvx` `{<key>}{<code>}` allows to use `#1` inside the code. +It is replaced by the actual `<value>`. Example: `\kvx{opt}{\message{opt is #1}}`, +then `\readkv{opt=HELLO}` prints \"opt is HELLO". + +The \^`\nokvx` `{<code>}` can declare a <code> processed for all <keys> +undeclared by \^`\kvx`. The `#1` and `#2` can be used in the <code>, +`#1` is <key>, `#2` is <value>. If `\nokvx` is unused then nothing is done +for undeclared <key>. Example: `\nokvx{\opwarnig{Unknown option "#1"}}`. + +The default dictionary name (where key-value pairs are processed) is +empty. You can use your specific dictionary by +\^`\kvdict``={<name>}`. Then `\redakv`, `\kv`, `\iskv`, `\kvx` and `\nokvx` +macros use this named dictionary of <key>/<value> pairs. +Package options can be processed when +`\kvdict={pkg:<pkg>}`, example is the `\mathset` macro in +\ulink[https://petr.olsak.net/ftp/olsak/optex/math-doc.pdf]{{\tt math.opm} package}. + +Recommendation: If the value of the key-value pair includes `=` or `,` or +`]`, then use the syntax `<key>={<value>}`. + +\_endinput + +2023-01-13 \kvx parameter added, \nokvx introduced. +2023-01-07 \kvdict, \kvx, \iskv added. +2020-12-21 Released diff --git a/macros/optex/base/lists.opm b/macros/optex/base/lists.opm index 189719302d..57b057d6c8 100644 --- a/macros/optex/base/lists.opm +++ b/macros/optex/base/lists.opm @@ -61,7 +61,7 @@ \_public \begitems \enditems \itemnum ; \_doc ---------------------------- - \`\novspaces` sets \`\listskipamount` to 0pt. + \`\novspaces` sets \^`\listskipamount` to 0pt. \_cod ---------------------------- \_def\_novspaces {\_removelastskip \_listskipamount=0pt \_relax} @@ -71,9 +71,9 @@ Various item marks are saved in `\_item:<letter>` macros. You can re-define then or define more such macros. The \`\style` `<letter>` does \`\_printitem``={\_item:<letter>}`. - More exactly: \^`\begitems` does `\_printitem=`\^`\defaultitem` first, - then \`\style` `<letter>` does \`\_printitem``={\_item:<letter>}` - when it is used and finally, `\_startitem` alias `*` uses `\_printitem`. + More exactly: \^`\begitems` does \^`\_printitem=`\^`\defaultitem` first, + then \^`\style` `<letter>` does \^`\_printitem``={\_item:<letter>}` + when it is used and finally, `\_startitem` alias `*` uses \^`\_printitem`. \_cod ----------------------------- \_def\_style#1{% diff --git a/macros/optex/base/math-macros.opm b/macros/optex/base/math-macros.opm index 83d3c5ab51..6e2365c9cc 100644 --- a/macros/optex/base/math-macros.opm +++ b/macros/optex/base/math-macros.opm @@ -368,7 +368,7 @@ \_doc ----------------------------- \`\big`, \`\Big`, \`\bigg`, \`\Bigg`, \`\bigl`, \`\bigm`, \`\bigr`, \`\Bigl`, \`\Bigm`, - \`\Bigr`, \`\biggl`, \`\biggm`, \`\biggr`, \`\Biggl`, \`\Biggm`, \`\Bigg`, \`\Biggr` + \`\Bigr`, \`\biggl`, \`\biggm`, \`\biggr`, \`\Biggl`, \`\Biggm`, \`\Biggr` are based on the \`\_scalebig` macro because we need the dependency on the various sizes of the fonts. \_cod ----------------------------- @@ -703,7 +703,7 @@ \_public\displaylines ; \_doc ----------------------------- - \`\openup`, \`\eqalignno` and `\leqalignno` macros are copied from + \`\openup`, \`\eqalignno` and \`\leqalignno` macros are copied from Plain \TeX/ unchanged. \_cod ----------------------------- diff --git a/macros/optex/base/more-macros.opm b/macros/optex/base/more-macros.opm index 418e71b774..8c62243234 100644 --- a/macros/optex/base/more-macros.opm +++ b/macros/optex/base/more-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \eoldef {OpTeX useful macros <2022-11-24>} % preloaded in format +\_codedecl \eoldef {OpTeX useful macros <2023-01-18>} % preloaded in format \_doc ----------------------------- We define \`\opinput` `{<file name>}` macro which @@ -261,7 +261,7 @@ \_public \cstochar ; \_doc ----------------------------- - You can use expandable \`\bp``{<dimen>}` convertor from + You can use expandable \`\bp``{<dimen>}` converter from \TeX/ `<dimen>` (or from an expression accepted by `\dimexpr` primitive) to a decimal value in big points (used as natural unit in the PDF format). So, you can write, for example: @@ -269,21 +269,32 @@ \pdfliteral{q \_bp{.3\hsize-2mm} \_bp{2mm} m 0 \_bp{-4mm} l S Q} \endtt You can use expandable \`\expr``{<expression>}` for analogical purposes. - It expands to the value of the `<expression>` at expand processor level - with \`\_decdigits` digits after the decimal point. + It expands to the value of the `<expression>` at expand processor level. The `<expression>` can include `+-*/()` and decimal numbers in common syntax. + The math functions (and pi constant) have to be prefixed by `math.`, + because it is processed by Lua interpreter. For + example `\expr{math.pi*math.sqrt(2)}`. + The list of available functions is in + \ulink[https://www.lua.org/manual/5.3/manual.html\#6.7]{Lua manual}. + + You can set the number of decimal digits after decimal point of the + results of `\bp` and `\expr` + by optional syntax `\bp[<digits>]{<dimen>}` and + `\expr[<digits>]{<expression>}`. Default is \`\_decdigits`. The usage of prefixed versions \`\_expr` or \`\_bp` is more recommended because a user can re-define the control sequences `\expr` or `\bp`. \_cod ----------------------------- \_def\_decdigits{3} % digits after decimal point in \_bp and \_expr outputs. -\_def\_pttopb{% - \_directlua{tex.print(string.format('\_pcent.\_decdigits f', +\_def\_pttopb#1{% + \_directlua{tex.print(string.format('\_pcent.#1f', token.scan_dimen()/65781.76))}% pt to bp conversion } -\def\_bp#1{\_ea\_pttopb\_dimexpr#1\_relax} -\def\_expr#1{\_directlua{tex.print(string.format('\_pcent.\_decdigits f',#1))}} +\_def\_bp{\_isnextchar[{\_bpA}{\_bpA[\_decdigits]}} +\_def\_bpA[#1]#2{\_pttopb{#1}\_dimexpr#2\_relax} +\_def\_expr{\_isnextchar[{\_exprA}{\_exprA[\_decdigits]}} +\_def\_exprA[#1]#2{\_directlua{tex.print(string.format('\_pcent.#1f',#2))}} \_public \expr \bp ; @@ -363,6 +374,7 @@ \_endcode % ------------------------------------- +2023-01-18 \bp, \expr have optional syntax for setting dec-digits 2022-11-24 \setpos, \posx, \posy moved from OpTeX trick here 2022-11-22 \docgen writes banner to log 2022-11-20 \docgen reads lines before \_codedecl in order to define pkg. version diff --git a/macros/optex/base/optex.ini b/macros/optex/base/optex.ini index 4941ead57c..3266cf0ab1 100644 --- a/macros/optex/base/optex.ini +++ b/macros/optex/base/optex.ini @@ -21,7 +21,7 @@ % OpTeX version -\def\optexversion{1.09 Dec 2022} +\def\optexversion{1.10 Feb 2023} \def\fmtname{OpTeX} \let\fmtversion=\optexversion diff --git a/macros/optex/base/others.opm b/macros/optex/base/others.opm index 98df836f76..cde2f02fa1 100644 --- a/macros/optex/base/others.opm +++ b/macros/optex/base/others.opm @@ -177,9 +177,9 @@ \_else % LuaTeX 1.14 or newer: \_doc ----------------------------- - We set `\partokenneame` to `\_par` in order to keep the name `\par` in - user name space. I.e. a user can say `\def\par{paragraph}` for example - without crash of processing the document. Se section~\ref[prefixed] for + We set `\partokenneame` to `\_par` in order to keep the name `\par` in the + public namespace for end users. I.e.\ a user can say `\def\par{paragraph}` for example + without crash of processing the document. Se section~\ref[namespaces] for more details about the name space concept.\nl Moreover, we set `\partokencontext` to one in order to the `\_par` token is inserted not only at empty lines, but also at the end of `\vbox`, `\vtop` and diff --git a/macros/optex/base/parameters.opm b/macros/optex/base/parameters.opm index 499aee8d45..855969f4de 100644 --- a/macros/optex/base/parameters.opm +++ b/macros/optex/base/parameters.opm @@ -205,6 +205,14 @@ \_public \picwidth \picheight ; \_doc ----------------------------- + \`\kvdict` is dictionary name when \~`\readkv`, \~`\kvx`, \~`\kv`, and \~`\iskv` are + processed. The default is empty. + \_cod ----------------------------- + +\_newtoks \_kvdict +\_public \kvdict ; + + \_doc ----------------------------- The \`\everytt` is the token list used in \^`\begtt`...\^`\endtt` environment and in the verbatim group opened by \^`\verbinput` macro. You can include a @@ -542,12 +550,10 @@ % \_shadow=N \_overlapmargins=N \_hhkern=3pt \_vvkern=3pt} \_newdimen \_roundness \_roundness=5mm % used in \clippingoval macro - \_public \ovalparams \circleparams \roundness ; \_doc ----------------------------- - \OpTeX/ defines \"Standard \OpTeX/ markup language"% - \fnote{Will be developed in 2021.} + \OpTeX/ defines \"Standard \OpTeX/ markup language" which lists selected commands from chapter~1 and gives their behavior when a converter from \OpTeX/ document to HTML or Markdown or \LaTeX/ is used. The structure-oriented commands are selected here, but the commands which diff --git a/macros/optex/base/prefixed.opm b/macros/optex/base/prefixed.opm index a599e0ec85..023f3bc4de 100644 --- a/macros/optex/base/prefixed.opm +++ b/macros/optex/base/prefixed.opm @@ -152,44 +152,70 @@ \_endcode %---------------------------------------------------- -\sec[prefixed] Concept of namespaces of control sequences +\sec[basic-code] Basic principles of \OpTeX/ sources -\secc Prefixing internal control sequences +\secc[namespaces] Concept of namespaces of control sequences -All control sequences used in \OpTeX/ are used and defined with `_` prefix. -The user can be sure that when he/she does `\def\foo` then neither internal macros of -\OpTeX/ nor \TeX/ primitives will be damaged. For example -`\def\if{...}` will not damage macros because \OpTeX/'s macros -are using `\_if` instead of `\if`. +\OpTeX/ sets the category code of the \"`_`" character to 11 (letter) +and it is never changed.\fnote +{This is only singular exception form category codes given by plain \TeX.} +So, we can always construct multiletter control sequence names from letters +`A`--`Z`, `a`--`z`, and `_`. The \"letter `_`" works in math mode as a subscript +constructor because it is set as math active character (see section~\ref[math-macros]). -All \TeX/ primitives are initialized with two representative control -sequences: `\word` and `\_word`, for example `\hbox` and `\_hbox`. -The first alternative is reserved for users or such control sequences -can be re-defined by a user. - -\OpTeX/ sets the character `_` as letter, so it can be used in -control sequences. When a control sequence begins with this character -then it means that it is a primitive or it is used in \OpTeX/ macros as -internal. User can redefine such prefixed control sequence only -if he/she explicitly knows what happens. - -We never change catcode of `_`, so internal macros can be -redefined by user without problems if it is desired. We don't need -something like `\makeatletter` from \LaTeX/. - -\OpTeX/ defines all new macros as prefixed. For public usage of such macros, -we need to set their non-prefixed versions. This is done by +We distinguish following namespaces for multiletter control sequences: +\begitems +* Only alphabetical names are in the {\em public namespace}. They are intended + for end users when creating a document. Sometimes it is called {\em user + namespace} too. For example `\hbox`, `\fontfam`, `\MyMacro`. +* Only alphabetical lowercase names prefixed by single \"`_`" are in the + {\em private namespace}. It is used in \OpTeX/ internal macros. + For example `\_hbox`, `\_fontsel`. +* Names in the form `\_<pkg>_<name>` are in the {\em package namespace}, + see section~\ref[pkg-namespace]. For example `\_qr_size`, `\_math_alist`. +* Names starting with two \"`_`" are in the {\em reserved namespace}. They can be + used for internal control sequences in font family files or in similar cases. +* Other names which include \"`_`" but not as the first character can be used + too, but with care, see the end of this section. +\enditems +All \TeX/ primitives are initialized with two control sequences with the +same meaning: {\em prefixed} control sequence +(in private namespace, for example `\_hbox`) +and {\em unprefixed} control sequence (in public namespace, for example `\hbox`). +All \OpTeX/ macros intended for end users are initialized in these two forms +too, for example `\_ref` and `\ref`. + +Users can declare any control sequences in the public namespace without worrying +that \OpTeX/ behavior is changed. This is because \OpTeX/ uses exclusively +prefixed control sequences in its macros. For example, a user can declare +`\def\fi{finito}` and nothing bad happens, if the user doesn't use `\fi` in +its original primitive meaning. You don't have to know all \TeX/ primitives +and \OpTeX/ macros, you can declare control sequences for your use in the +public namespace without limitations and nothing bad will happen. + +You can use control sequences from private or package namespace in +a \"read-only manner" without changing \OpTeX/ behavior too. +On the other hand, if you re-define a control sequence in the private name +space, the \OpTeX/ behavior can be changed. You can do it +but we suppose that you know what you are doing and what \OpTeX/ +behavior is changed. + +All multiletter control sequences declared by \OpTeX/ are defined in the private +namespace first (`\_def\_macro{...}`). If the declared control sequences are +intended for end users too then they are exported to the public namespace +after that. It is done by the \^`\public` macro: \begtt \catcode`\<=13 \public <list of control sequences> ; \endtt - For example \^`\public`` \foo \bar ;` does `\let\foo=\_foo`, `\let\bar=\_bar`. -At the end of each code segment in \OpTeX/, the `\_public` macro is used. You -can see which macros are defined for public usage in that code segment. +There is an exception of the above mentioned principle. Control sequences +which are alternatives to math characters (`\alpha`, `\forall`, `\subset` etc.) +are declared only in public name space if they are not used in any internal +\OpTeX/ macros. -The macro \^`\private` does the reverse job of `\public` with the same syntax. +The macro \^`\private` does the reverse job of \^`\public` with the same syntax. For example `\private \foo \bar ;` does `\let\_foo=\foo`, `\let\_bar=\bar`. This should be used when an unprefixed variant of a control sequence is declared already but we need the prefixed variant too. @@ -199,45 +225,33 @@ In this documentation: if both variants of a control sequence are declared the unprefixed variant. The code typically defines the prefixed variant and then the \^`\public` (or `\_public`) macro is used. -\secc[user-ns] Namespace of control sequences for users - -Users can (re)define or (re)declare any control sequence with a name without any `_`. -This does not make any problem in internal \OpTeX/ macros.\fnote -{The token `\par` is in user name space too from \OpTeX/ 1.04+ and -Lua\TeX/ 1.14, see also the end of section~\ref[others].} - -User can define or declare control sequences with `_` character, for -example `\my_control_sequence`, but with the following exceptions: - -\begitems -* Control sequences which begin with `_` are reserved for \TeX/ primitives, - \OpTeX/ internal macros and packages internal macros. -* Multiletter control sequences in the form - `\<word>_` or `\<word>_<one-letter>`, where - <word> is a sequence of letters, are inaccessible, because they - are interpreted as `\<word>` followed by `_` or as `\<word>` followed by - `_<one-letter>`. This is important for writing math, for example: -\begtt \adef-{_} - \int-a^b ... is interpreted as \int _a^b - \max-M ... is interpreted as \max _M - \alpha-{ij} ... is interpreted as \alpha _{ij} -\endtt - This feature is implemented using Lua code at input processor level, see - the section~\ref[math-macros] for more details. You can deactivate this feature by - \^`\mathsboff`. After this, you can still write - `$`$\int$`_a^b$` (Unicode) or `$\int _a^b$` % $∫_a^b$ (Unicode) or $\int _a^b$ - without problems but `\int``_a^b` yields to undefined control sequence - `\int``_a`. You can activate this feature again by \^`\mathsbon`. The - effect will take shape from next line read from input file. -* Control sequences in the form `\_<pkg>_<word>` is intended for package - writers as internal macros for a package with `<pkg>` identifier, - see section~\ref[pkg-namespace]. -\enditems - The single-letter control sequences like `\%`, `\$`, `\^` etc. are not used in internal macros. Users can redefine them, but (of course) some classical features can be lost (printing percent character by `\%` for example). +It is very tempting to use control sequence names with `_` in order to +distinguish more words in the sequence name. If the first character isn't +`_` then such a name is outside private and package namespaces, so they can +be used for various purposes. For example `\my_control_sequence`. But there +is an exception: control sequences in the form `\<word>_` or `\<word>_<one-letter>`, +where <word> is a sequence of letters, are inaccessible, because they +are interpreted as `\<word>` followed by `_` or as `\<word>` followed by +`_<one-letter>`. This feature is activated because we want to write math +formulae as in plain \TeX, for example: +\begtt + \int_a^b ... is interpreted as \int _a^b + \max_M ... is interpreted as \max _M + \alpha_{ij} ... is interpreted as \alpha _{ij} +\endtt +It is implemented using Lua code at input processor level, see +the section~\ref[math-macros] for more details. You can deactivate this feature by +\^`\mathsboff`. After this, you can still write +`$`$\int$`_a^b$` (Unicode) or `$\int _a^b$` % $∫_a^b$ (Unicode) or $\int _a^b$ +without problems but `\int``_a^b` yields to undefined control sequence +`\int``_a`. You can activate this feature again by \^`\mathsbon`. The +effect will take shape from next line read from input file. + + \secc Macro files syntax Segments of \OpTeX/ macros or external macro packages @@ -272,7 +286,7 @@ put macros for creating your documentation between first pair of \^`\_doc` ... \^`\_cod` used after \^`\_endcode`. These macros should \^`\load[doc]` and must be finished by \^`\bye`. Then you have code+documentation together in a single file and -user can generate the documentation of our package by +user can generate the documentation of your package by \^`\docgen` used at command line: \begtt optex -jobname pkgname-doc '\docgen pkgname' @@ -307,10 +321,10 @@ does `\let\foo = \_<pkg>_foo` for each given sequence when \^`\_namespace{<pkg>}` is declared. Moreover, it prints a warning if `\foo` is defined already. The \^`\_nsprivate` macro does reverse operation to it without warnings. Example: you can define `\def\.macro{...}` and then -set it to the user name space by `\_nspublic \macro;`. +set it to the public namespace by `\_nspublic \macro;`. It could happen that a package writer needs to declare a control sequence -(say `\foo`) directly without setting it in `\_<pkg>_foo` name space +(say `\foo`) directly without setting it in `\_<pkg>_foo` namespace followed by using \^`\_nspublic`. The \^`\newpublic` prefix should be used in this case, for example `\_newpublic\_def\foo` or `\_newpublic\_chardef\foo` or `\_newpublic{\_long\_def}\foo`. The \^`\newpublic``<do>\<sequence>` prints @@ -338,9 +352,9 @@ If you are writing a macro file that is intended to be published for \OpTeX/, then you are greatly welcome. You should follow these rules: \begitems -* Don't use control sequences from the user namespace in the macro +* Don't use control sequences from the public namespace in the macro bodies if there is no explicit and documented reason to do this. -* Don't declare control sequences in the user namespace if there are no +* Don't declare control sequences in the public namespace if there are no explicit and documented reasons to do this. * Use control sequences from \OpTeX/ and primitive namespace in read-only mode, if there is not an explicit and documented reason to @@ -368,11 +382,12 @@ used directly in \OpTeX/ and from other published macros. This extension `.opm` has precedence before `.tex` when the \^`\load` macro is used. -The `qrcode.opm` is the first example of how an external macro file for \OpTeX/ +The `math.opm` is a good example of how an external macro file for \OpTeX/ can look like. \endinput +2023-01-30 doc. about namespaces rewritten 2022-11-25 \_resetnamespace: moved \gdef\_namesp:#1 {} to \_namespace 2022-11-24 \newpublic introduced, \_checkexists with only two parameters. 2022-11-22 \currfile introduced and used in \_codedecl diff --git a/macros/optex/base/references.opm b/macros/optex/base/references.opm index 9da2bca30f..56ad7ad589 100644 --- a/macros/optex/base/references.opm +++ b/macros/optex/base/references.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \ref {References <2021-04-13>} % preloaded in format +\_codedecl \ref {References <2022-01-22>} % preloaded in format \_doc ---------------------------- \`\_Xpage` `{<gpageno>}{<pageno>}` saves the parameter pair into \`\_currpage`. @@ -121,5 +121,6 @@ See section \ref[ref-file] for more information about `.ref` file concept. \_endinput +2022-01-22 ... extended format for \ref, \pgref 2021-04-13 ... \_slideshook introduced (used by \slides) 2020-03-03 ... released diff --git a/macros/optex/base/sections.opm b/macros/optex/base/sections.opm index 7d7a78232b..7940a47bfa 100644 --- a/macros/optex/base/sections.opm +++ b/macros/optex/base/sections.opm @@ -171,7 +171,7 @@ First, we read the optional parameter `[<label>]`, if it exists. The `\chap`, `\sec` and `\secc` macro reads its parameter using \^`\scantoeol`. This causes that they cannot be used inside other macros. - Use \`\_inchap`, \`\_insec`, and \`\_insecc` macros directly in such case. + Use \^`\_inchap`, \^`\_insec`, and \^`\_insecc` macros directly in such case. \_cod ---------------------------- \_optdef\_chap[]{\_trylabel \_scantoeol\_inchap} diff --git a/macros/optex/base/slides.opm b/macros/optex/base/slides.opm index 39267064ba..84cf6f5db3 100644 --- a/macros/optex/base/slides.opm +++ b/macros/optex/base/slides.opm @@ -277,7 +277,7 @@ \_def\layers{\_layers} \_doc ----------------------------- - We must to redefine \`\fnotenumpages` because the data from `.ref` file + We must to redefine \^`\fnotenumpages` because the data from `.ref` file are less usable for implementing such a feature: the footnote should be in more layers repeatedly. But we can suppose that each page starts by `\pg;` macro, so we can reset the footnote counter by diff --git a/macros/optex/base/table.opm b/macros/optex/base/table.opm index 1866c0486d..a249f1e30a 100644 --- a/macros/optex/base/table.opm +++ b/macros/optex/base/table.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \table {Basic macros for OpTeX <2022-05-03>} % preloaded in format +\_codedecl \table {Basic macros for OpTeX <2022-12-26>} % preloaded in format \_doc ----------------------------- The result of the \`\table``{<declaration>}{<data>}` macro is inserted into @@ -229,9 +229,9 @@ We don't want vertical line after red A to be in red. \_cod ----------------------------- -\_def\_tabdeclarec{\_the\_tabiteml \_begingroup\_hfil##\_unsskip\_hfil\_endgroup \_the\_tabitemr} -\_def\_tabdeclarel{\_the\_tabiteml \_begingroup ##\_unsskip\_hfil\_endgroup \_the\_tabitemr} -\_def\_tabdeclarer{\_the\_tabiteml \_begingroup\_hfil##\_unsskip\_endgroup \_the\_tabitemr} +\_def\_tabdeclarec{\_the\_tabiteml \_hfil{##}\_unsskip \_hfil \_the\_tabitemr} +\_def\_tabdeclarel{\_the\_tabiteml {##}\_unsskip \_hfil\_the\_tabitemr} +\_def\_tabdeclarer{\_the\_tabiteml \_hfil{##}\_unsskip \_the\_tabitemr} \_doc ----------------------------- The \`\_paramtabdeclarep``{<data>}` is invoked when `p{<data>}` @@ -587,6 +587,7 @@ after the second one. \_endinput +2022-12-26 \tabdeclare: use {##} in order to allow a\over b in table items 2022-05-03 \_let\_tablereplstring\_relax removed and {...} encloses whole \_tableB body 2022-05-02 \_tablereplstrings put in group: bug fix \table in \halign 2022-02-25 {}->\(begin|end)group in \_tabdeclare(l|r|c), bug when \tabitem(l|r)={$} fixed. diff --git a/macros/optex/base/unimath-codes.opm b/macros/optex/base/unimath-codes.opm index 418d0d28aa..66be7487d4 100644 --- a/macros/optex/base/unimath-codes.opm +++ b/macros/optex/base/unimath-codes.opm @@ -1,27 +1,82 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \_ncharrmA {Uni math codes <2022-11-20>} % preloaded on demand by \loadmath +\_codedecl \_ncharrmA {Uni math codes <2023-01-17>} % preloaded on demand by \loadmath \_doc ----------------------------- - The control sequences for `\alpha`, `\beta` etc are redefined here. - The `\alpha` expands to the character with Unicode `"03B1`, this is a normal - character $α$. You can type it directly in your editor if you know how - to do this. + Unicode math font includes all typical math alphabets together, user needs no + load more \TeX/ math families. These math alphabets are encoded by + different parts of Unicode table. We need auxiliary macros for setting + mathcodes by selected math alphabet. + \nl + \`\_umathrange` `{<from->-<to>}<class><family>\<first>` sets `\Umathcode`s + of the characters in the interval `<from>-<to>` to `\<first>`, + `\<first>+1`, `\<first>+2` + etc., but \`\_umathcharholes` are skipped + (`\_umathcharholes` are parts of the Unicode table not designed for math + alphabets, they cause that the math alphabets are + not continuously spread out in the table; I mean that the + designers were under the influence of drugs when they created + this part of the Unicode table). + The `<from>-<to>` clause includes characters like~`A-Z`. + Note that the `\_umathrange` sets the \`\_classfam` macro as <class> + <family> for later use. \_cod ----------------------------- -\_umathnumB="0391 -\_greekdef \Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta \Iota \Kappa - \Lambda \Mu \Nu \Xi \Omicron \Pi \Rho \varTheta \Sigma \Tau \Upsilon \Phi - \Chi \Psi \Omega \_relax +\_newcount\_umathnumA \_newcount\_umathnumB -\_umathnumB="03B1 -\_greekdef \alpha \beta \gamma \delta \varepsilon \zeta \eta \theta \iota \kappa - \lambda \mu \nu \xi \omicron \pi \rho \varsigma \sigma \tau \upsilon - \varphi \chi \psi \omega \vardelta \epsilon \vartheta \varkappa \phi - \varrho \varpi \_relax +\_def\_umathcorr#1#2{\_ea#1\_ea{\_the#2}} +\_def\_umathprepare#1{\_def\_umathscanholes##1[#1]##2##3\_relax{##2}} +\_def\_umathvalue#1{\_ea\_umathscanholes\_umathcharholes[#1]{#1}\_relax} + +\_def\_umathcharholes{% holes in math alphabets: + [119893]{"210E}[119965]{"212C}[119968]{"2130}[119969]{"2131}% + [119971]{"210B}[119972]{"2110}[119975]{"2112}[119976]{"2133}[119981]{"211B}% + [119994]{"212F}[119996]{"210A}[120004]{"2134}% + [120070]{"212D}[120075]{"210C}[120076]{"2111}[120085]{"211C}[120093]{"2128}% + [120122]{"2102}[120127]{"210D}[120133]{"2115}[120135]{"2119} + [120136]{"211A}[120137]{"211D}[120145]{"2124}% +} +\_def\_umathrange#1#2#3#4{\_umathnumB=#4\_def\_classfam{#2 #3 }\_umathrangeA#1} +\_def\_umathrangeA#1-#2{\_umathnumA=`#1\_relax + \_loop + \_umathcorr\_umathprepare\_umathnumB + \_Umathcode \_umathnumA = \_classfam \_umathcorr\_umathvalue{\_umathnumB} + \_ifnum\_umathnumA<`#2\_relax + \_advance\_umathnumA by1 \_advance\_umathnumB by1 + \_repeat +} \_doc ----------------------------- - The math alphabets are declared here using the + A few math characters have very specific Unicode and must be handled + individually. We can run \`\_umathrangespec``<list of characters>\relax` + just after \^`\_umathrange`. The `\_umathnumB` must be set to the first + destination code. The \^`\_umathrangespec` applies to each character from + the <list of characters> this: + `\Umathcode``<char-code>=\_classfam\_umathnumB` and increments + `\_umathnumB`. If `\_umathnumB=0` then it applies + `\Umathcode``<char-code>=\_classfam <char-code>`. + The \^`\_classfam` and `\_umathnumB` were typically set by previous call + of the \^`\_umathrange` macro. + \_cod ----------------------------- + +\_def\_umathrangespec#1{\_ifx#1\_relax \_else + \_Umathcode `#1=\_classfam \_ifnum\_umathnumB=0 `#1 \_else \_umathnumB\_fi + \_unless\_ifnum\_umathnumB=0 \_advance\_umathnumB by1 \_fi + \_ea\_umathrangespec \_fi +} + + \_doc ----------------------------- + The math alphabets are set by + \`\_rmvariables`, \`\_bfvariables`, \`\_itvariables`, \`\_bivariables`, + \`\_calvariables`, \`\_bcalvariables`, \`\_frakvariables`, + \`\_bfrakvariables`, \`\_bbvariables`,\nl \`\_sansvariables`, + \`\_bsansvariables`, \`\_isansvariables`, \`\_bisansvariables`, + \`\_ttvariables`,\nl \`\_itgreek`, \`\_rmgreek,` \`\_bfgreek`, \`\_bigreek`, + \`\_bsansgreek`, \`\_bisansgreek`,\nl \`\_itGreek`, \`\_rmGreek`, \`\_bfGreek`, + \`\_biGreek`, \`\_bsansGreek`, \`\_bisansGreek`,\nl \`\_rmdigits`, + \`\_bfdigits`, \`\_bbdigits`, \`\_sansdigits`, \`\_bsansdigits`, + \`\_ttdigits`.\nl + They are declared using the \^`\_umathrange {<range>}<class><family><starting-code>` macro. \_cod ----------------------------- @@ -68,30 +123,12 @@ \_protected\_def\_bigreek {\_umathrangegreek71\_greekbia} \_protected\_def\_bsansgreek {\_umathrangegreek71\_greeksna} \_protected\_def\_bisansgreek{\_umathrangegreek71\_greeksia} -\_protected\_def\_itGreek {\_umathrangeGREEK71\_greekitA \_setnablait} -\_protected\_def\_rmGreek {\_umathrangeGREEK71\_greekrmA \_setnablarm} -\_protected\_def\_bfGreek {\_umathrangeGREEK71\_greekbfA \_setnablabf} -\_protected\_def\_biGreek {\_umathrangeGREEK71\_greekbiA \_setnablabi} -\_protected\_def\_bsansGreek {\_umathrangeGREEK71\_greeksnA \_setnablabsans} -\_protected\_def\_bisansGreek{\_umathrangeGREEK71\_greeksiA \_setnablabisans} - - \_doc ----------------------------- - \`\_setnabla` is used in order to `\nabla` behaves like uppercase Greek - letter, similar like `\Delta`. It depends on `\bf`, `\it` etc. selectors. - If you want to deactivate this behavior, use `\def\_setnabla#1 {}`. - \_cod ----------------------------- - -\_def \_setnabla {\_Umathcode"2207 = 7 1} -\_def \_setnablarm {\_setnabla"02207 } -\_def \_setnablabf {\_setnabla"1D6C1 } -\_def \_setnablait {\_setnabla"1D6FB } -\_def \_setnablabi {\_setnabla"1D735 } -\_def \_setnablabsans {\_setnabla"1D76F } -\_def \_setnablabisans {\_setnabla"1D7A9 } - - \_doc ----------------------------- - Digits are configured like math alphabets. - \_cod ----------------------------- +\_protected\_def\_itGreek {\_umathrangeGREEK71\_greekitA} +\_protected\_def\_rmGreek {\_umathrangeGREEK71\_greekrmA} +\_protected\_def\_bfGreek {\_umathrangeGREEK71\_greekbfA} +\_protected\_def\_biGreek {\_umathrangeGREEK71\_greekbiA} +\_protected\_def\_bsansGreek {\_umathrangeGREEK71\_greeksnA} +\_protected\_def\_bisansGreek{\_umathrangeGREEK71\_greeksiA} \_chardef\_digitrmO=`0 \_chardef\_digitbfO="1D7CE @@ -108,6 +145,59 @@ \_protected\_def\_ttdigits {\_umathrange{0-9}71\_digitttO} \_doc ----------------------------- + The control sequences for `\alpha`, `\beta`, etc.\ are redefined here. + The `\alpha` will expand to the character with Unicode `"03B1`, this is a normal + character $α$. You can type it directly in your editor if you know how + to do this. These sequences are declared by + `\_greekdef``<list of sequences>\relax`. + \_cod ----------------------------- + +\_def\_greekdef#1{\_ifx#1\_relax + \_else + \_edef#1{\_Uchar\_umathnumB}% + \_advance\_umathnumB by 1 + \_ea\_greekdef \_fi +} +\_umathnumB="0391 +\_greekdef \Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta \Iota \Kappa + \Lambda \Mu \Nu \Xi \Omicron \Pi \Rho \varTheta \Sigma \Tau \Upsilon \Phi + \Chi \Psi \Omega \_relax + +\_umathnumB="03B1 +\_greekdef \alpha \beta \gamma \delta \varepsilon \zeta \eta \theta \iota \kappa + \lambda \mu \nu \xi \omicron \pi \rho \varsigma \sigma \tau \upsilon + \varphi \chi \psi \omega \_relax + + \_doc ----------------------------- + The \`\_umathrangeGREEK``<class><family><first>` and + \`\_umathrangegreek``<class><family><first>` macros + for setting math codes of Greek characters are defined here. They use \^`\_umathrange` + for general codes but the exceptions must be handled by the + \^`\_umathrangespec` macro. + The exceptions are seven Greek characters: + $\epsilon, \vartheta, \varkappa, \phi, \varrho, \varpi, \nabla$. + The first six of these characters should behave as lowercase Greek letters + and the last one `\nabla` is uppercase Greek letter. + \_cod ----------------------------- + +\_def\epsilon{^^^^03f5} \_def\vartheta{^^^^03d1} \_def\varkappa{^^^^03f0} +\_def\phi{^^^^03d5} \_def\varrho{^^^^03f1} \_def\varpi{^^^^03d6} +\_def \nabla{^^^^2207} + +\_def\_umathrangeGREEK#1#2#3{\_umathrange{^^^^0391-^^^^03a9}#1#2#3% \Alpha-\Omega + \_resetnabla % you can do \let\_resetnabla=\relax if you don't want to change \nabla shape +} +\_def\_resetnabla {% + \_ifnum\_umathnumB<950 \_umathnumB=0 \_else \_advance\_umathnumB by1 \_fi + \_umathrangespec ^^^^2207\_relax % \nabla +} +\_def\_umathrangegreek#1#2#3{% + \_umathrange{^^^^03b1-^^^^03c9}#1#2#3% \alpha-\omega + \_ifnum#3=\_greekrma \_umathnumB=0 \_else \_advance\_umathnumB by2 \_fi + \_umathrangespec ^^^^03f5^^^^03d1^^^^03f0^^^^03d5^^^^03f1^^^^03d6\_relax % \epsilon-\varpi +} + + \_doc ----------------------------- The math alphabets \`\cal`, \`\bbchar`, \`\frak`, \`\script` are re-defined here. The \`\_marm`, \`\_mabf`, \`\_mait`, \`\_mabi`, \`\_matt` used in \^`\rm`, \^`\bf`, \^`\it`, \^`\bi` are re-defined too.\nl @@ -145,7 +235,7 @@ Each Unicode slot carries information about math type. This is saved in the file `MathClass-15.txt` which is copied to `mathclass.opm` The file has the following format: - {\vitt{mathclass.opm}\verbinput (70-85) mathclass.opm } + {\vitt{mathclass.opm}\verbinput (70-85) mathclass.opm }% We have to read this information and convert it to the `\Umathcode`s. \_cod ----------------------------- @@ -170,34 +260,62 @@ \_doc ----------------------------- Each math symbol has its declaration in the file `unicode-math-table.tex` which is copied to `unimath-table.opm`. The file has the following format: - {\vitt{unimath-table.opm}\verbinput (36-41) unimath-table.opm } - We have to read this information and set given control sequences to - the relevant Unicode characters using `\chardef`. We don't use `\mathchardef` - for them because the want to manage the matcodes (class, family, slot) - only at single place: at Unicode characters. Control sequeces declared here - are only pointers to these Unicode characters. Exceptions are delimiters and - math accents.\nl - If the character is delimiter then we declare \_d:<sequence> to be the - `\chardef` equivalent of the character and `\let<sequence>=<character>` - because `\left`, `\right` doesn't like `\chardef` equivalent of the - character although it has its own delcode. + {\vitt{unimath-table.opm}\verbinput (36-41) unimath-table.opm }% + We have to read this information and set given control sequences as macros + which expand to the given Unicode character. This solution enables to use + such control sequences in PDF outlines where they expand to the appropriate + Unicode character. + We don't use `\mathchardef`, we set the mathcodes (class, family, slot) + only at single place: for Unicode math characters. For example for we + define `\times`: + \begtt + \def\times{^^d7} \Umathcode "D7 = 2 1 "D7 + \endtt + Because math codes of Greek upright letters vary depending on + \^`\_itgreek`, \^`\_bfgreek`, + etc.\ macros, we need to keep the access directly to these characters. + We define `\mupalpha`, `\mupbeta`, ..., `\mupomega` macros as a code from + PUA (Private Use Area) of Unicode table and set mathcode of these + codes to the real upright alpha, beta, ..., omega. \_cod ----------------------------- \_begingroup % \input unimath-table.opm (it is a copy of unicode-math-table.tex): + \_umathnumB="F800 % pointer to the Private User Area \_def\UnicodeMathSymbol #1#2#3#4{% - \_chardef#2=#1 % control sequence is only pointer to Unicode character + \_edef#2{\_Uchar #1}% control sequence is a macro which expands to the Unicode character \_ifnum#1=\_Umathcodenum#1 \_Umathcode#1=0 1 #1 \_fi % it isn't set by mathclass.opm - \_ifx#3\_mathopen \_setdelimiter#2\_fi - \_ifx#3\_mathclose \_setdelimiter#2\_fi - \_ifx#3\mathfence \_setdelimiter#2\_fi \_ifx#3\_mathaccent \_protected\_def#2{\_Umathaccent fixed 7 1 #1 }\_fi + \_ifnum#1>"390 \_ifnum#1<"3F6 + \_edef#2{\_Uchar\_umathnumB}% \mupAlpha, \mupBeta, \mupalpha, \mupbeta, ... + \_Umathcode\_umathnumB=0 1 #1 + \_advance\_umathnumB by1 + \_fi\_fi % \muGreek, \mugreek symbols } \_def\mathfence{F}% - \_def\_setdelimiter#1{\_expanded{\_let\_cs{_d:\_csstring#1}=#1\_let#1=\Uchar#1}} \_globaldefs=1 \_input unimath-table.opm \_endgroup \_doc ----------------------------- + The macro `\int` expands to an <int-character>. We save the `\mathcode` + of the <int-character> to `\_int:<int-character>` using `\Umathchardef` and + declare <int-character> as math-active and define it + as `\_int:<int-character> \_nolimits`. Moreover, we define `\intop` as + `\_int:<int-character>` (it is the itegral with limits like in plain \TeX). + We do this with other int-like operators listed below too. + \_cod ----------------------------- + +\_def\_intwithnolimits#1{\_ifx#1\_relax \_else + \_ea\_Umathcharnumdef\_csname _int:#1\_endcsname=\_Umathcodenum\_ea`#1 % + \_ea\_def \_csname\_csstring#1op\_ea\_endcsname\_ea{\_csname _int:#1\_endcsname}% + \_bgroup \_lccode`\~=\_ea`#1 \_lowercase{\_egroup + \_ea\_def\_ea~\_ea{\_csname _int:#1\_endcsname\_nolimits}\_mathcode`~="8000 }% + \_ea \_intwithnolimits \_fi +} +\_intwithnolimits \int \iint \iiint \oint \oiint \oiiint + \intclockwise \varointclockwise \ointctrclockwise \sumint \iiiint \intbar \intBar \fint + \pointint \sqint \intlarhk \intx \intcap \intcup \upint \lowint \_relax + + \_doc ----------------------------- Many special characters must be declared with care... \_cod ----------------------------- @@ -227,29 +345,8 @@ \_protected\_def \_cuberoot {\_Uradical 1 "0221B } \_protected\_def \_fourthroot {\_Uradical 1 "0221C } -\_def \nabla {^^^^2207} % \nabla behaves as uppercase Gereek letter, see \_setnabla - \_public \sqrt \cuberoot \fourthroot ; - \_doc ----------------------------- - We save the `\mathcode` of `\int` to `\_intop` using `\Umathchardef` and - declare Unicode character `\int` as math-active and define it - as `\_intop\_nolimits`. We define `\intop` as `\_intop` for users - (intergral with normal limits). - We do this with other int-like operators listed below too. - \_cod ----------------------------- - -\_def\_intwithnolimits#1{\_ifx#1\_relax \_else - \_ea\_Umathcharnumdef\_csname _\_csstring#1op\_endcsname=\_Umathcodenum#1% - \_ea\_def \_csname\_csstring#1op\_ea\_endcsname\_ea{\_csname _\_csstring#1op\_endcsname}% - \_bgroup \_lccode`\~=#1 \_lowercase{\_egroup - \_ea\_def\_ea~\_ea{\_csname _\_csstring#1op\_endcsname\_nolimits}\_mathcode`~="8000 }% - \_ea \_intwithnolimits \_fi -} -\_intwithnolimits \int \iint \iiint \oint \oiint \oiiint - \intclockwise \varointclockwise \ointctrclockwise \sumint \iiiint \intbar \intBar \fint - \pointint \sqint \intlarhk \intx \intcap \intcup \upint \lowint \_relax - \_protected\_def \_overbrace #1{\_mathop {\_Umathaccent 7 1 "023DE{#1}}\_limits} \_protected\_def \_underbrace #1{\_mathop {\_Umathaccent bottom 7 1 "023DF{#1}}\_limits} \_protected\_def \_overparen #1{\_mathop {\_Umathaccent 7 1 "023DC{#1}}\_limits} @@ -366,6 +463,8 @@ \_let \upvartheta=\mupvartheta \_let \upphi=\mupphi \_let \upvarpi=\mupvarpi +\_let \varTheta=\mupvarTheta +\_let \vardelta=\delta \_doc ----------------------------- The \`\not` macro is redefined here. If the `\_not!<char>` is defined @@ -450,10 +549,9 @@ Example of using additional math font is in section 5.3 in the \ulink[http://petr.olsak.net/ftp/olsak/optex/optex-math.pdf]{\tt optex-math.pdf} documentation - -You can combine more Unicode math fonts in single formula simply -by the `\addUmathfont` macro, see -\ulink[http://petr.olsak.net/optex/optex-tricks.html#addumathfont]{\OpTeX/ trick 0030}. +More examples are in the +\ulink[http://petr.olsak.net/optex/optex-tricks.html]{OpTeX tricks} and in the +\ulink[https://petr.olsak.net/ftp/olsak/optex/math-doc.pdf]{math.opm} package. See \url{http://tex.stackexchange.com/questions/308749} for technical details about Unicode-math. @@ -461,6 +559,11 @@ for technical details about Unicode-math. \_endinput History: +2023-01-17 \int operators re-implemented +2023-01-15 \mupalpha, \mupbeta etc. have codes from PUA +2023-01-15 math control sequences are macros, they expand to math characters +2023-01-14 \epsilon, \vartheta, \varkappa, \phi, \varrho, \varpi, ... bug fix +2023-01-13 \mupalhpha, \mupbeta, ... bug fix 2022-11-20 \mathfence's get delimiter code too 2022-11-18 Delimiters re-implemented 2022-11-17 \Umathchardef replaced by \chardef diff --git a/macros/optex/base/unimath-macros.opm b/macros/optex/base/unimath-macros.opm index 96f87a6a9b..d4cd9e5540 100644 --- a/macros/optex/base/unimath-macros.opm +++ b/macros/optex/base/unimath-macros.opm @@ -1,6 +1,6 @@ %% This is part of the OpTeX project, see http://petr.olsak.net/optex -\_codedecl \loadmath {Unicode Math fonts <2022-12-01>} % preloaded in format +\_codedecl \loadmath {Unicode Math fonts <2023-01-17>} % preloaded in format \_doc ----------------------------- \`\loadmath` `{<Unicode-math font>}` loads the given font. It does: @@ -143,66 +143,6 @@ \_def\_mparams{} \_doc ----------------------------- - Unicode math font includes all typical math alphabets together, user needs not to - load more \TeX/ math families. These math alphabets are encoded by - different parts of Unicode table. We need auxiliary macros for setting - mathcodes by selected math alphabet. - \nl - \`\_umathrange` `{<from->-<to>}<class><family>\<first>` sets `\Umathcode`s - of the characters in the interval `<from>-<to>` to `\<first>`, - `\<first>+1`, `\<first>+2` - etc., but \`\_umathcharholes` are skipped - (`\_umathcharholes` are parts of the Unicode table not designed for math - alphabets, they cause that the math alphabets are - not continuously spread out in the table; I mean that the - designers were under the influence of drugs when they created - this part of the Unicode table). - The `<from>-<to>` clause includes characters like~`A-Z`. - \nl - \`\_umahrangegreek` `\<first>` is the same as - `\_umathrange {<alpha>-<omega>}\<first>`. - \nl - \`\_umahrangeGREEK` `\<first>` is the same as - `\_umathrange {<Alpha>-<Omega>}\<first>`. - \nl - \`\_greekdef` `<control sequences> \_relax` defines each control sequence - as a normal character with codes `\_umathnumB`, `\_umathnumB+1`, - `\_umathnumB+2` etc. It is used for redefinig the contol sequences for - math Greek `\alpha`, `\beta`, `\gamma` etc. - \_cod ----------------------------- - -\_newcount\_umathnumA \_newcount\_umathnumB - -\_def\_umathcorr#1#2{\_ea#1\_ea{\_the#2}} -\_def\_umathprepare#1{\_def\_umathscanholes##1[#1]##2##3\_relax{##2}} -\_def\_umathvalue#1{\_ea\_umathscanholes\_umathcharholes[#1]{#1}\_relax} - -\_def\_umathcharholes{% holes in math alphabets: - [119893]{"210E}[119965]{"212C}[119968]{"2130}[119969]{"2131}% - [119971]{"210B}[119972]{"2110}[119975]{"2112}[119976]{"2133}[119981]{"211B}% - [119994]{"212F}[119996]{"210A}[120004]{"2134}% - [120070]{"212D}[120075]{"210C}[120076]{"2111}[120085]{"211C}[120093]{"2128}% - [120122]{"2102}[120127]{"210D}[120133]{"2115}[120135]{"2119} - [120136]{"211A}[120137]{"211D}[120145]{"2124}% -} -\_def\_umathrange#1#2#3#4{\_umathnumB=#4\_def\_tmp{#2 #3 }\_umathrangeA#1} -\_def\_umathrangeA#1-#2{\_umathnumA=`#1\_relax - \_loop - \_umathcorr\_umathprepare\_umathnumB - \_Umathcode \_umathnumA = \_tmp \_umathcorr\_umathvalue{\_umathnumB} - \_ifnum\_umathnumA<`#2\_relax - \_advance\_umathnumA by1 \_advance\_umathnumB by1 - \_repeat -} -\_def\_umathrangeGREEK{\_umathrange{^^^^0391-^^^^03a9}} -\_def\_umathrangegreek{\_umathrange{^^^^03b1-^^^^03d6}} -\_def\_greekdef#1{\_ifx#1\_relax \_else - \_begingroup \_lccode`X=\_umathnumB \_lowercase{\_endgroup \_def#1{X}}% - \_advance\_umathnumB by 1 - \_ea\_greekdef \_fi -} - - \_doc ----------------------------- \`\addUmathfont` `<fam> {[<normal-font>]}{<ffeatures>} {[<bold-font>]}{<ffeatures>} {<factor>}` allocates new <fam> using \^`\newfam` and adds loading this font to the \~`\normalmath` and \~`\boldmath` macros. Note that allocationos using @@ -230,16 +170,34 @@ } \_doc ----------------------------- + The math characters can be given directly (by their Unicode) or by a macro + like `\doteq`, `\times`, etc. These macros simply expand to the math character + with its Unicode. And this math character has its `\Umathcode` given by + <class>, <family>, <slot-number>. Sometimes, we may want to get these + quantities from the given Unicode math character by our macros. It is + possible by \`\themathcodeclass``<math-char>`, + \`\themathcodefam``<math-char>` and \`\themathcodechar``<math-char>` macros. + The parameter <math-char> is a math character or it is a macro like `\doteq`, `\times`. + Moreower, \`\thedelcodefam``<math-char>` and \`\thedelcodechar``<math-char>` + return delcode quaitities of givem math character. + \_cod ----------------------------- + +\_def\_getmathcode#1#2{\_directlua{tex.print(tex.get#2code(token.scan_int())[#1])}} +\_def\_themathcodeclass #1{\_getmathcode 1{math}\_ea`#1 } +\_def\_themathcodefam #1{\_getmathcode 2{math}\_ea`#1 } +\_def\_themathcodechar #1{\_getmathcode 3{math}\_ea`#1 } +\_def\_thedelcodefam #1{\_getmathcode 1{del}\_ea`#1 } +\_def\_thedelcodechar #1{\_getmathcode 2{del}\_ea`#1 } + +\_public \themathcodeclass \themathcodefam \themathcodechar \thedelcodefam \thedelcodechar ; + + \_doc ----------------------------- \`\mathchars` `<fam> {<list of sequences>}` saves <fam> to \`\_mafam` and runs for each sequence from the <list of sequences> - the relevant code settings. - The `\directlua` chunk prints the 8-digits hexadecimal code of the - sequence followed by the sequence itself. The digts are scanned by \`\_mathcharsB` - and new `\Umathcode` is declared.\nl - If there exist \_d:<sequence> (i.e.\ it is delimiter) then `\Udelcode` is - redeclared too. Finally, in case of `\int`-like operators the - `\_intop` sequence is redeclared by `\Umathchardef`. Note that the used - primitives have the syntax: + the relevant code settings using `\Umathcode` primitive. + In case of `\int`-like operators the <math class>=8 and we only + re-declare `\_int:<int-character>` as an operator with the new \^`\_mafam`. + Note that the used primitives have the syntax: \begtt \catcode`<=13 \Umathchardef <sequence> = <math class> <math family> <slot number> \Umathcode <code> = <math class> <math family> <slot number> @@ -249,20 +207,13 @@ \_def\_mathchars {\_afterassignment\_mathcharsA \_chardef\_mafam=} \_def\_mathcharsA #1{\_foreach #1\_do{% - \_ifcsname _d:\_csstring##1\_endcsname \_ea \_mathcharsD \_csname _d:\_csstring##1\_endcsname - \_else \_mathcharsC ##1\_fi -}} -\_def\_mathcharsC #1{\_ea\_mathcharsB - \_directlua{tex.print(string.format("\_pcent08X", \_the\_Umathcode#1))}#1% -} -\_def\_mathcharsB #1#2#3#4#5#6#7#8#9{% #9 is given \math-sequence - \_ifcsname _\_csstring#9op\_endcsname - \_ea \_Umathchardef \_csname _\_csstring#9op\_endcsname=1 \_mafam #9\_relax + \_chardef\_tmp=\_themathcodeclass##1\_relax + \_ifnum\_tmp=8 % \int, \iint, \oint, etc. + \_ea\_Umathchardef \_csname _int:##1\_endcsname =1 \_mafam \_ea`##1 \_else - \_Umathcode "#4#5#6#7#8=\_numexpr"#3/2\_relax \_mafam "#4#5#6#7#8 + \_Umathcode \_ea`##1=\_tmp \_mafam \_themathcodechar##1 \_fi -} -\_def\_mathcharsD #1{\_mathcharsC #1\_relax \_Udelcode #1=\_mafam #1\_relax} +}} \_doc ----------------------------- \`\mathcodes` `<fam> {<list of pairs>}` sets mathcodes of given @@ -276,10 +227,10 @@ \_def\_mathcodes{\_afterassignment\_mathcodesA\_chardef\_mafam=} \_def\_mathcodesA#1{% \_foreach #1\_do ##1##2{% - \_ea\_foreach\_expanded{##2}\_do{\_Umathcode `####1=##1\_mafam`####1}% + \_ea\_foreach\_expanded{##2}\_do{\_Umathcode `####1=##1\_mafam \_ea`####1}% }% } -\_def\_Urange #1-#2{\_fornum `#1..`#2\_do{\_Uchar##1 }} +\_def\_Urange #1-#2{\_fornum \_ea`#1..\_ea`#2\_do{\_Uchar##1 }} \_public \addUmathfont \mathchars \mathcodes \Urange ; @@ -351,7 +302,8 @@ in the <list-of-pairs> is `<class-number><character>` (separated by optional space) or `<class-number>{<list-of-characters>}`. The <list-of-characters> includes declared characters or \^`\Urange` `<from>-<to>` which is equal to the list of characters beginning <from> and ending <to>, for example -`\Urange a-d` is equal to `abcd`. +`\Urange a-d` is equal to `abcd`. The characters can be given directly or +by the math sequences like `\times`, `\doteq` too. The \^`\mathcodes` macro declares mathcode of given characters internally by \begtt \catcode`<=13 @@ -385,6 +337,9 @@ the section~\ref[math-macros]. \_endinput +2023-01-17 \mathchars: \int operators re-implemented +2023-01-15 \_def\_umathrange moved to unimath-codes.opm +2023.01-15 \themathcodeclass etc. introduced 2022-12-01 reading number by \_loadumathfamily more robust 2022-11-18 \mathchars improved, \Udelcodes are set too, \addUmathfont uses \ahead 2022-11-17 \Umathchardef replaced by \chardef diff --git a/macros/optex/doc/optex-doc.pdf b/macros/optex/doc/optex-doc.pdf Binary files differindex 666e8793e6..ed937d191e 100644 --- a/macros/optex/doc/optex-doc.pdf +++ b/macros/optex/doc/optex-doc.pdf diff --git a/macros/optex/doc/optex-doc.tex b/macros/optex/doc/optex-doc.tex index de9639a576..bbb19e44f2 100644 --- a/macros/optex/doc/optex-doc.tex +++ b/macros/optex/doc/optex-doc.tex @@ -21,9 +21,9 @@ \tit Format Based on Plain \TeX/ and OPmac\fnotemark1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\hfill Version 1.09 +\hfill Version 1.10 -\centerline{\it Petr Olšák, 2020, 2021, 2022} +\centerline{\it Petr Olšák, 2020, 2021, 2022, 2023} \bigskip \centerline{\url{http://petr.olsak.net/optex}} diff --git a/macros/optex/doc/optex-userdoc.tex b/macros/optex/doc/optex-userdoc.tex index e04014b991..937952079a 100644 --- a/macros/optex/doc/optex-userdoc.tex +++ b/macros/optex/doc/optex-userdoc.tex @@ -961,7 +961,7 @@ verbatim text is \~`\code{<text>}` (see below). If the numerical register \^`\ttline` is set to the non-negative value then display verbatim will number the lines. The first line has the number \^`\ttline+1` and when the verbatim ends then the \^`\ttline` value is equal to the -number of the last line printed. Next \^`\begtt...`\^`\endtt` environment will follow +number of the last line printed. Next \^`\begtt``...`\^`\endtt` environment will follow the line numbering. \OpTeX/ sets \^`\ttline=-1` by default. The indentation of each line in display verbatim is controlled by @@ -991,7 +991,7 @@ There is an alternative to \^`\everytt` named \^`\everyintt` which is used for in-line verbatim surrounded by an \^`\verbchar` or processed by the \~`\code` command. -The \^`\everytt` is applied to all \^`\begtt...`\^`\endtt` environments (if it is not +The \^`\everytt` is applied to all \^`\begtt``...`\^`\endtt` environments (if it is not declared in a group). There are tips for such global `\everytt` definitions here: \begtt \adef!{\char9251 } @@ -1001,7 +1001,7 @@ declared in a group). There are tips for such global `\everytt` definitions here \endtt \new -If you want to apply a special code only for one \^`\begtt...`\^`\endtt` +If you want to apply a special code only for one \^`\begtt``...`\^`\endtt` environment then don't set any \^`\everytt` but put desired material at the same line where \^`\begtt` is. For example: @@ -1051,12 +1051,12 @@ the first opening bracket. They are processed in the local group. For example, `\verbinput \hsize=20cm (-) program.c`. The \~`\ttline` influences the line numbering by the same way as in -\~`\begtt...`\~`\endtt` environment. If \~`\ttline=-1` then real line numbers are +\~`\begtt``...`\~`\endtt` environment. If \~`\ttline=-1` then real line numbers are printed (this is the default). If \code{\\ttline<-1} then no line numbers are printed. The \^`\verbinput` can be controlled by \^`\everytt`, \^`\ttindent` just like -in \~`\begtt...`\~`\endtt`. +in \~`\begtt``...`\~`\endtt`. The \~`\begtt`...\~`\endtt` pair or \~`\verbinput` can be used for listings of codes. Automatic syntax highlighting is possible, for example @@ -1760,7 +1760,7 @@ The list of packages supported by \OpTeX/ follows. Most of them are directly par * \ulink[https://github.com/vlasakm/optex-minim]{\tt minim-mp.opm} enables `\directmetapost` using \ulink[https://ctan.org/pkg/minim-mp]{\tt minim-mp} and \ulink[https://ctan.org/pkg/minim]{\tt minim} packages. -* \ulink[https://ctan.org/tex-archive/macros/luatex/optex/pdfextra/pdfextra-doc.pdf]{\tt pdfextra.opm} +* \ulink[https://ctan.org/tex-archive/macros/luatex/generic/pdfextra/pdfextra-doc.pdf]{\tt pdfextra.opm} allows the use of many extra features from PDF standard (by M. Vlasák). \enditems See these files in `optex/pkg/` or `optex/<pkgname>` for more information about @@ -1890,9 +1890,9 @@ put it as the first command in your document: %%%%%%%%%%%%%%%%%%%%%%%%%% All \TeX/ primitives and almost all \OpTeX/ macros are accesible by two -names: `\foo` (public or user name space) and `\_foo` (private name space). +names: `\foo` (public or user namespace) and `\_foo` (private name space). For example `\hbox` and `\_hbox` means the same \TeX/ primitive. More about -it is documented in section~\ref[prefixed]. +it is documented in section~\ref[namespaces]. If this manual refers `\foo` then `\_foo` equivalent exists too. For example, we mention the `\addto` macro below. The `\_addto` equivalent exists too, but it @@ -1901,10 +1901,10 @@ equivalent does not exist. For example, we mention the `\_codedecl` macro below, this macro is not available as `\codedecl`. If you are writing a document or macros specific for the document, then use -simply user namespace (`\foo`). If you are writing more general macros, -then use private namespace (`\_foo`), but you should declare your own namespace +simply public namespace (`\foo`). If you are writing more general macros, +then you should declare your own namespace by \~`\_namespace` macro and you have to follow the naming discipline described in -section~\ref[pkg-namespace]. +sections~\ref[namespaces] and \ref[pkg-namespace]. The alphabetically sorted list of macros typically usable for macro writers follows. More information about such macros can be found in the technical documentation. @@ -1944,7 +1944,8 @@ documentation. Example: \~`\isinlist\list{<text>}\iftrue` does `\iftrue` if <text> is in `\list`.\nl \^`\isnextchar`` <char>{<text1>}{<text2>}` performs <text1> if next character is <char>, else <text2>.\nl -\~`\kv` `{<key>}` expands to value when key-value parameters are used.\nl +\~`\kv` `{<key>}` expands to value when key-value parameters are used. + See also \~`\iskv`, \~`\readkv`, \~`\kvx`, \~`\nokvx`.\nl \^`\loop` `...` \^`\repeat` is classical Plain \TeX/ loop.\nl \^`\mathstyles`` {<math list>}` enables to create macros dependent on current math style.\nl \~`\_namespace`` {<pkg>}` declares name space used by package writers.\nl @@ -1959,7 +1960,6 @@ documentation. provide coordinates of absolute position of the \~`\setpos``[<label>]`. \~`\private`` <sequence> <sequence> ... ;` declares <sequence>s for private name space.\nl \~`\public`` <sequence> <sequence> ... ;` declares <sequence>s for public name space.\nl -\~`\readkv` `\macro` reads parameters from `\macro` in key-value format.\nl \^`\replstring`` \macro{<stringA>}{<stringB>}` replaces all <stringA> to <stringB> in `\macro`.\nl \^`\sdef` `{<string>}<parameters>{<body>}` behaves like `\def\<string><parameters>{<body>}`.\nl \^`\setctable` and \^`\restorectable` manipulate with stack of catcode tables.\nl diff --git a/macros/optex/pkg/math.opm b/macros/optex/pkg/math.opm index 5b0f29dd2f..50853b013a 100644 --- a/macros/optex/pkg/math.opm +++ b/macros/optex/pkg/math.opm @@ -3,11 +3,36 @@ % This file can serve as an template for other package files % See end of the file for more information -\_def\_math_version {0.02, 2022-11-26} -\_codedecl \replacemissingchars {Doing math more comfortable <\_math_version>} +\_def\_math_version {0.08, 2023-01-28} +\_codedecl \replacemissingchars {Doing math more comfortably <\_math_version>} \_namespace{math} \_doc + The `math` package provides options, they can be declared using + the \`\mathset``{<options>}` macro. For example `\mathset {vert, dots}`. + If you create your own package with options, provide a similar + `\<pkg>set` macro. The \`\.kv` macro is similar to \OpTeX's `\kv`, but + with specific `pkg:math` dictionary. + \_cod + +\_def\.mathset #1{% + \_edef\.restorekvdict{\_kvdict{\_the\_kvdict}}% + \_kvdict{pkg:math}% + \_nokvx {\_opwarning{\_the\_kvdict: unknown option "##1", ignored}}% + \_kvx {vert} {\.smartvert}% sets | as math active, to do better |x| or ||x|| + \_kvx {dots} {\.smartdots}% \dots behaves like \ldots or \cdots + \_kvx {bfserif} {\.bfserif}% \bf, \bi select fonts with serifs + \_kvx {rmchars} {\.rmchars{##1}}% does \.rmchars{<list>} + \_kvx {vargreek} {\.vargreek{##1}}% does \.vargreek{<list>} + \_kvx {text} {\.dotext{##1}}% does \.dotext{<list>} + \_readkv{#1}% + \.restorekvdict +} +\_def\.kv #1{\_trycs{_kv:pkg:math:#1}{\_kvunknown}}% for accessing values given by \mathset + +\_nspublic \mathset ; + + \_doc \`\bigp`, \`\Bigp`, \`\biggp`, \`\Biggp`, \`\autop`, \`\normalp` are inspired from \tricklink[bigp]{0094} \_cod @@ -22,11 +47,12 @@ \_isequal .{#1}\_iffalse #1\_fi \_let\.bigleft=#2\_let\.bigright=#3\_nospacefuturelet\.next\.fparamA} \_def\.fparamA{% - \_ifx\.next(\.afterrelax{\.fparamB()}\_fi - \_ifx\.next[\.afterrelax{\.fparamB[]}\_fi - \_ifx\.next\{\.afterrelax{\.fparamB\{\}}\_fi - \_ifx\.next\_bgroup \_def\.lparen{\{}\_def\.rparen{\}}\.afterrelax{\.fparamC}\_fi - \_relax + \_casesof \.next + ( {\.fparamB()}% + [ {\.fparamB[]}% + \{ {\.fparamB\{\}}% + \_bgroup {\_def\.lparen{\{}\_def\.rparen{\}}\.fparamC}% + \_finc {}% } \_def\.fparamB#1#2{% \_def\.lparen{#1}\_def\.rparen{#2}% @@ -34,16 +60,14 @@ \.next } \_def\.fparamC#1{% - \_ifx\.bigleft\_left \_mathopen{}\_fi + \_ifx\.bigleft\_left \_mathopen{}\_bgroup\_fi \.bigleft\.lparen{#1}\.bigright\.rparen - \_ifx\.bigright\_right \_mathclose{}\_fi + \_ifx\.bigright\_right \_egroup\_fi } -\_def\.afterrelax#1#2\_relax{\_fi#1} - \_nspublic \bigp \Bigp \biggp \Biggp \autop \normalp ; \_doc - We need macro \`\.ensurebalanced` for balancing nested parentheses from + We need macro \`\.ensurebalanced``<open-b><close-b><macro>` for balancing nested parentheses from \tricklink[balancing]{0043}. We use `trick` namespace for these macros. \_cod @@ -97,7 +121,7 @@ \_nspublic \smartdots ; \_doc - \`\smartvert` sets `|` as math-active charcter and declares it + \`\smartvert` sets `|` as math-active character and declares it equal to `\.autovert` macro. This macro checks two variants: there is single `|` or there is double `||`. It runs \`\.autovertA` or \`\.autoVertA`. These macros find the closing `|` or `||` and use @@ -105,7 +129,7 @@ is declared here if a user want to use a single vertical bar. \_cod -\_newpublic \_mathchardef \_singlevert=\_mathcode`| +\_newpublic\_mathchardef \singlevert=\_mathcode`| \_def\.autovert {\_isnextchar|{\.autoVertA}{\.autovertA}} \_def\.autovertA #1|{\_mathopen{}\_mathclose{\_left|#1\_right|}} \_def\.autoVertA|#1||{\_mathopen{}\_mathclose{\_left‖#1\_right‖}} @@ -117,37 +141,68 @@ \_doc The control sequences \`\N`, \`\Z`, \`\Q`, \`\R`, \`\C` \`\sgn`, \`\argmin`, \`\argmax`, \`\grad`, \`\rank`, \`\tr`, \`\diag`, \`\Span`, - \`\Rng`, \`\Null`, \`\Ker`, \`\Res`, \`\tg`, \`\arctg`, + \`\Rng`, \`\Null`, \`\Ker`, \`\Res`, \`\tg`, \`\cotg`, \`\arctg`, \`\arccotg`, \`\frac`, \`\dfrac`, \`\tfrac`, \`\.` are defined directly in the user space by \o`\_newpublic`. + The \`\.pdef` is a shortcut for `\protected\def`. \_cod -\_newpublic\_def \N {{\_bbchar N}} -\_newpublic\_def \Z {{\_bbchar Z}} -\_newpublic\_def \Q {{\_bbchar Q}} -\_newpublic\_def \R {{\_bbchar R}} -\_newpublic\_def \C {{\_bbchar C}} - -\_newpublic\_def \sgn {\_mathop{\_rm sgn}\_nolimits} -\_newpublic\_def \argmin {\_mathop{\_rm argmin}} -\_newpublic\_def \argmax {\_mathop{\_rm argmax}} -\_newpublic\_def \grad {\_mathop{\_rm grad}\_nolimits} -\_newpublic\_def \rank {\_mathop{\_rm rank}\_nolimits} -\_newpublic\_def \tr {\_mathop{\_rm tr}\_nolimits} -\_newpublic\_def \diag {\_mathop{\_rm diag}\_nolimits} -\_newpublic\_def \Span {\_mathop{\_rm Span}\_nolimits} -\_newpublic\_def \Rng {\_mathop{\_rm Rng}\_nolimits} -\_newpublic\_def \Null {\_mathop{\_rm Null}\_nolimits} -\_newpublic\_def \Ker {\_mathop{\_rm Ker}\_nolimits} -\_newpublic\_def \Res {\_mathop{\_rm Res}\_nolimits} -\_newpublic\_def \tg {\_mathop{\_rm tg}\_nolimits} -\_newpublic\_def \arctg {\_mathop{\_rm arctg}\_nolimits} - -\_newpublic\_def \frac #1#2{{{#1}\_over#2}} -\_newpublic\_def \dfrac #1#2{{\_displaystyle{{#1}\_over#2}}} -\_newpublic\_def \tfrac #1#2{{\_textstyle{{#1}\_over#2}}} - -\_newpublic\_def \.#1{{\_bf#1}} +\_def\.pdef{\_protected\_def} + +\_newpublic\.pdef \N {{\_bbchar N}} +\_newpublic\.pdef \Z {{\_bbchar Z}} +\_newpublic\.pdef \Q {{\_bbchar Q}} +\_newpublic\.pdef \R {{\_bbchar R}} +\_newpublic\.pdef \C {{\_bbchar C}} + +\_newpublic\.pdef \sgn {\_mathop{\_rm sgn}\_nolimits} +\_newpublic\.pdef \argmin {\_mathop{\_rm argmin}} +\_newpublic\.pdef \argmax {\_mathop{\_rm argmax}} +\_newpublic\.pdef \grad {\_mathop{\_rm grad}\_nolimits} +\_newpublic\.pdef \rank {\_mathop{\_rm rank}\_nolimits} +\_newpublic\.pdef \tr {\_mathop{\_rm tr}\_nolimits} +\_newpublic\.pdef \diag {\_mathop{\_rm diag}\_nolimits} +\_newpublic\.pdef \Span {\_mathop{\_rm Span}\_nolimits} +\_newpublic\.pdef \Rng {\_mathop{\_rm Rng}\_nolimits} +\_newpublic\.pdef \Null {\_mathop{\_rm Null}\_nolimits} +\_newpublic\.pdef \Ker {\_mathop{\_rm Ker}\_nolimits} +\_newpublic\.pdef \Res {\_mathop{\_rm Res}\_nolimits} +\_newpublic\.pdef \tg {\_mathop{\_rm tg}\_nolimits} +\_newpublic\.pdef \cotg {\_mathop{\_rm cotg}\_nolimits} +\_newpublic\.pdef \arctg {\_mathop{\_rm arctg}\_nolimits} +\_newpublic\.pdef \arccotg {\_mathop{\_rm arccotg}\_nolimits} + +\_newpublic\.pdef \frac #1#2{{{#1}\_over#2}} +\_newpublic\.pdef \dfrac #1#2{{\_displaystyle{{#1}\_over#2}}} +\_newpublic\.pdef \tfrac #1#2{{\_textstyle{{#1}\_over#2}}} + +\_newpublic\.pdef \.#1{{\_bf#1}} + + \_doc + \`\eqsystem``{<equations>}` saves its parameter to `\.tmpb` + and does a collection of `\_replstring`s. It replaces all spaces by `&` + (but ignores the optional first and last space), it removes spaces before `\cr`, + it precedes `\mathord` before all `-` + (but not if the minus is alone in the column) and runs `\halign`. + The \n`\baselineskip` is enlarged by \O`\openup`\`\eqskip`. + Each item adds 0.5\`\eqsep` around it and \`\eqfil` to the left side and + `\hfil` to the right side. + \_cod + +\_protected \_optdef\.eqsystem[]#1{\_vcenter{% + \_def\.tmpb{\.bb#1\.bb}\_replstring\.tmpb{ }{&}% + \_replstring\.tmpb{\.bb&}{}\_replstring\.tmpb{&\.bb}{}\_replstring\.tmpb{&\cr}{\cr}% + \_replstring\.tmpb{-}{\_mathord-}\_replstring\.tmpb{&\_mathord-&}{&-&}% + \_let ~=\_relax + \_the\_opt \_relax \_openup\.eqskip + \_halign{&\_the\.eqfil\_kern.5\.eqsep$\_displaystyle{{}##{}}$\_kern.5\.eqsep\_hfil\_cr + \.tmpb\_crcr}% +}} +\_let\.bb=\_empty +\_newdimen\.eqskip +\_newdimen\.eqsep +\_newtoks\.eqfil \.eqfil={\_hfill} +\_nspublic \eqsystem \eqskip \eqsep \eqfil ; \_doc The \`\toright` and \`\toleft` macros are based on the @@ -168,7 +223,7 @@ \_doc The \`\subeqmark` works because the internal \O`\_thednum` is re-defined. The \`\.dnumpost` is added here. If you want to use another format - for \O`\_thednum` then you have to add the \`\.dnumpost` to it too. + for \O`\_thednum` then you have to add the \^`\.dnumpost` to it too. \_cod \_def \_thednum {(\_the\_dnum \.dnumpost)} @@ -178,12 +233,43 @@ \_nspublic \subeqmark ; \_doc + \`\bfserif` re-defines internal \OpTeX/ \O`\_mabf` and \O`\_mabi` macros. + \_cod + +\_def\bfserif{% + \_protected\_def\_mabf {\_inmath{\_bfvariables\_bfgreek\_bfGreek\_bfdigits}}% + \_protected\_def\_mabi {\_inmath{\_bivariables\_bigreek\_bfGreek\_bfdigits}}% +} + + \_doc + \`\rmchars``{<list>}` is implemented using \O`\foreach`. The list is + expanded first because we want to expand control sequences like `\alpha` + to a real character $\_rmgreek \alpha$.\nl + \`\vargreek``{<list>}` is implemented using \O`\foreach`. The + parameter is not expanded because we want to keep control sequences like + `\alpha` unchanged. + \_cod + +\_def\.rmchars#1{\_ea\_foreach \_expanded{#1}\_do{\_ifx,##1\_else\.rmchar##1\_fi}} +\_def\.rmchar#1{\_Umathcode`#1=0 1 `#1 } + +\_def\.vargreek#1{\_foreach#1\_do{\_ifx,##1\_else \.vargreekchar##1\_fi}} +\_def\.vargreekchar#1{% + \_ifcsname var\_csstring#1\_endcsname \_slet{\_csstring#1}{var\_csstring#1}% + \_else \_opwarning{\_string\vargreek: the \_bslash var\_csstring#1\_space doesn't exists}% + \_fi +} +\_nspublic \rmchars \vargreek ; + + \_doc \`\textvariables`, \`\textdigits`, \`\textmoremath` initialize new two families 5, 6 using `\.textmathini` and sets `\mathcode`s of given characters to these families. Moreover, `\textvariables` adds `\fam` register setting to `\rm` and `\it` selectors and re-set Greek variables to use only math font (because we - are not sure if Greek letters are in the current text fonts). + are not sure if Greek letters are in the current text fonts).\nl + \`\.dotext``{<list of words>}` runs `\.text<word>` for each <word> in the list. + It is used when the option `text={<list of words>}` is used. \_cod \_def\.textmathini{% @@ -204,8 +290,8 @@ \_addto\_marm {\_fam5 }\_addto\_mait{\_fam6 }% \_protected\_def\_itgreek {\_umathrangegreek01\_greekita}% \_protected\_def\_rmgreek {\_umathrangegreek01\_greekrma}% - \_protected\_def\_itGreek {\_umathrangeGREEK01\_greekitA \_setnablait} - \_protected\_def\_rmGreek {\_umathrangeGREEK01\_greekrmA \_setnablarm} + \_protected\_def\_itGreek {\_umathrangeGREEK01\_greekitA} + \_protected\_def\_rmGreek {\_umathrangeGREEK01\_greekrmA} \_itgreek \_rmGreek } \_def\.textdigits {\.textmathini \_mathcodes 5 {7{\_Urange 0-9}}} @@ -213,6 +299,9 @@ \_mathcodes 5 {5{!?} 2{*+-} 3{=<>} 6{,:;} 0{./|} 4{([\{} 5{\})]}}% \_Umathcode `- = 2 5 "2212 % hyphen behaves like minus in math mode } +\_def\.dotext#1{\_foreach #1 \_do + ##1 {\_trycs{_math_text##1}{\_opwarning{text option: "##1" unknown}}}} + \_nspublic \textvariables \textdigits \textmoremath ; \_doc @@ -226,7 +315,7 @@ replaced again if a new `\replacemissingchars` is used. \_cod -\_def\.rlist{} +\_def\.rlist{\sqrt\cuberoot\fourthroot} % they cannot be replaced by \mathchars \_def\.replacemissingchars#1{% \_def\.alist{}\_def\.clist{} \_def\UnicodeMathSymbol##1##2##3##4{% @@ -242,9 +331,9 @@ } \_input unimath-table.opm \_wlog{^^J\_string\replacemissingchars: From \_string\fam=\_string#1 is printed now:^^J% - CHARACTERS: \.clist^^JACCENTS: \.alist^^J}% - \_ea\_mathchars \_expanded{\_noexpand#1{\.clist}}% - \_edef\.rlist{\.rlist\.clist\.alist}% + CHARACTERS: \_unexpanded\_ea{\.clist}^^JACCENTS: \_unexpanded\_ea{\.alist}^^J}% + \_def\.tmp{\_mathchars #1}\_ea\.tmp\_ea{\.clist}% + \_ea\_addto \_ea\.rlist \_ea{\.clist}\_ea\_addto \_ea\.rlist \_ea{\.alist}% \_def\.alist{}\_def\.clist{}\_let\UnicodeMathSymbol=\_undefined } \_nspublic \replacemissingchars ; @@ -258,20 +347,28 @@ \_def\.scriptspaces #1#2#3#4{% \_Umathordrelspacing\_scriptstyle=\.orzeromu{#1}\_relax \_Umathrelordspacing\_scriptstyle=\.orzeromu{#1}\_relax + \_Umathrelopspacing \_scriptstyle=\.orzeromu{#1}\_relax \_Umathordrelspacing\_crampedscriptstyle=\.orzeromu{#1}\_relax \_Umathrelordspacing\_crampedscriptstyle=\.orzeromu{#1}\_relax + \_Umathrelopspacing \_crampedscriptstyle=\.orzeromu{#1}\_relax \_Umathordbinspacing\_scriptstyle=\.orzeromu{#2}\_relax \_Umathbinordspacing\_scriptstyle=\.orzeromu{#2}\_relax + \_Umathbinopspacing \_scriptstyle=\.orzeromu{#2}\_relax \_Umathordbinspacing\_crampedscriptstyle=\.orzeromu{#2}\_relax \_Umathbinordspacing\_crampedscriptstyle=\.orzeromu{#2}\_relax + \_Umathbinopspacing \_crampedscriptstyle=\.orzeromu{#2}\_relax \_Umathordrelspacing\_scriptscriptstyle=\.orzeromu{#3}\_relax \_Umathrelordspacing\_scriptscriptstyle=\.orzeromu{#3}\_relax + \_Umathrelopspacing \_scriptscriptstyle=\.orzeromu{#3}\_relax \_Umathordrelspacing\_crampedscriptscriptstyle=\.orzeromu{#3}\_relax \_Umathrelordspacing\_crampedscriptscriptstyle=\.orzeromu{#3}\_relax + \_Umathrelopspacing \_crampedscriptscriptstyle=\.orzeromu{#3}\_relax \_Umathordbinspacing\_scriptscriptstyle=\.orzeromu{#4}\_relax \_Umathbinordspacing\_scriptscriptstyle=\.orzeromu{#4}\_relax + \_Umathbinopspacing \_scriptscriptstyle=\.orzeromu{#4}\_relax \_Umathordbinspacing\_crampedscriptscriptstyle=\.orzeromu{#4}\_relax \_Umathbinordspacing\_crampedscriptscriptstyle=\.orzeromu{#4}\_relax + \_Umathbinopspacing \_crampedscriptscriptstyle=\.orzeromu{#4}\_relax } \_def\.orzeromu#1{\_ifx^#1^0mu\_else#1\_fi} @@ -294,9 +391,13 @@ The following macros are defined in this package: \~`\smartvert` declares \"`|`" for better spacing. * There are many common math macros for sets or for operators, for example \~`\R` or \~`\sgn`. +* \~`\eqsystem` enables to write systems of equations comfortably, * \~`\toright`, \~`\toleft` puts the \o`\eqmark` to desired position, \~`\subeqmark` prints the given suffix as a part of the equation mark. * \~`\scriptspaces` sets more spaces around rel, bin in script and scripscript styles. +* \~`\bfserif` sets `\bf` and `\bi` for math typesetting as for bold-serif, bold-italic-serif. +* \~`\rmchars` sets selected characters printed as `\rm`, + \~`\vargreek` sets Greek leters to their variants. * \~`\textvariables`, \~`\textdigits`, \~`\textmoremath` enables characters from used text font in math mode (variables, digits, more characters). @@ -304,6 +405,21 @@ The following macros are defined in this package: for printing them from additional math font. \enditems +Six options are provided by the `math` package. You can set them by +\^`\mathset``{<options>}` after `\load[math]`, for example +`\mathset{dots, vert, vargreek={\epsilon,\rho}}`. The options are: +\begitems +* `dots` sets more inteligent `\dots`, the same as \~`\smartdots`. +* `vert` sets more inteligent `|`, the same as \~`\smartvert`. +* `bfserif` sets bold-serif, bold-italic-serif, the same as \~`\bfserif`. +* `rmchars={<list>}` sets `\rm` for selected characters, the same as \~`\rmchars`, + see section~\ref[rmchars]. +* `vargreek={<list>}` sets variants for Greek letetters, the same as \~`\vargreek`, + see section~\ref[rmchars]. +* `text={<list>}` sets \~`\textvariables`, \~`\textdigits`, or \~`\textmoremath`, + see section~\ref[textvars]. +\enditems + This package is not definitive. I plan to add more features in new versions if needed. Moreover, this package gives an example for package writers how to write their own packages, see section~\ref[pkgtemplate]. @@ -387,27 +503,67 @@ $$ } $$ + \sec Basic and typical macros for sets, functions etc. These typical macros are defined in `math.opm`: \^`\N` for $\N$, \^`\Z` for $\Z$, \^`\Q` for $\Q$, \^`\R` for $\R$, \^`\C` for $\C$, \^`\sgn`, \^`\argmin`, \^`\argmax`, \^`\grad`, \^`\rank`, \^`\tr`, \^`\diag`, \^`\Span`, \^`\Rng`, -\^`\Null`, \^`\Ker`, \^`\Res`, \^`\tg`, \^`\arctg`. +\^`\Null`, \^`\Ker`, \^`\Res`, \^`\tg`, \^`\cotg`, \^`\arctg`, \^`\arccotg`. I hate the \^`\frac`, \^`\dfrac` and \^`\tfrac` macros defined in \LaTeX/ but someone may want to use them. This package defines them. But I note: usage of `$1\over2$` for $1\over2$ is much more understandable than \LaTeX's `$\frac12$`. -The vectors and matrices are ususally printed by `{\bf A}{\bf x}`. +The vectors and matrices are usually printed by `{\bf A}{\bf x}`. The package provides a shortcut `\.<letter>` to do the same, so user can write `\.A\.x` for multiplication of a matrix $\.A$ by a vector $\.x$. We strictly don't recommend usage of `\.`, `\v`, `\=`, etc.\ for accents, so `math.opm` can define `\.` differently than the classical meaning \"dotaccent". + +\sec System of equations printed by `\eqsystem` + +The \^`\eqsystem``{<equations>}` enables to write systems of equations more +comfortably. The equations are separated by `\cr` and the aligned columns +are separated by space. For example: +\begtt +$$ + \eqsystem{ x + y - 2z = 10 \cr + 2x - 7y + z = 13 \cr + -x + y ~ ~ = -5 } +$$ +\endtt +prints +$$ + \eqsystem{ x + y - 2z = 10 \cr + 2x - 7y + z = 13 \cr + -x + y ~ ~ = -5 } +$$ +Note that empty columns have to be filled by `~` mark. +There are columns for variables (possibly multiplied by a constant) and for +binary operators `+` and `-` or relations `=`, `>` etc. or constants. Each column +is aligned to right. The number of columns is unlimited (we have 7 columns in +the example above). All given equations are packed to the `\vcenter` box. + +The spaces between lines are enlarged by the value of \^`\eqskip` +and the horizontal spaces between columns are enlaged by \^`\eqsep`. +Both registers are set to 0\,pt by default. + +The \^`\eqfil` register is \"left filler" applied to each item in the \^`\eqsystem` columns. +Its default is `\eqfil={\hfill}`. The right filler is hardwired and it is `\hfil`. +This makes columns aligned to right by default. For example, when you set +`\eqfil={\hfil}` then you have columns centered. + +The \^`\eqsystem` macro allows optional parameter which is processed inside +group before printing equations. You can do local settings here, for example +`\eqsystem[\eqskip=2pt \eqsep=5pt]{...}`. + + \sec Equation marks in atypical cases -We want to put equation marks `\eqmark` in more lines in display mode when we +We may want to put equation marks `\eqmark` in more lines in display mode when we are using macros not designed for such case. For example in the lines of the `\cases` macro: @@ -425,7 +581,7 @@ The \^`\toright`\o`\eqmark` is used here. Analogically, The position of these marks are correct after second or more \TeX/ run because \TeX/ needs to read data from its previous run in this case. -Sometime we want to declare a bunch of equations with the same numeric +Sometimes we want to declare a bunch of equations with the same numeric equation marks but with different suffixes, for example (1.1a), (1.1b). We provide the macro \^`\subeqmark``<suffix>` here. If `<suffix>` is `a` or `A` then \^`\subeqmark` starts a new bunch of @@ -435,12 +591,10 @@ You can put `[<label>]` after `<suffix>` for referencing purposes. Example: \begtt -$$\adef~{\kern.5em } - \eqalignno{ - x + 2y + 3z &= 600 & \subeqmark a \cr - 12x + ~y - 3z &= -7 & \subeqmark b[label] \cr - 4x - ~y + 5z &= ~5 & \subeqmark c \cr - } +$$ \eqsystem[\eqskip=3pt]{ + x + 2y + 3z = 600 \toright{\subeqmark a}\cr + 12x + y - 3z = -7 \toright{\subeqmark b[label]}\cr + 4x - y + 5z = 5 \toright{\subeqmark c}\cr } $$ The equation~\ref[label] has negative right side. Moreover, it applies $$ @@ -448,11 +602,10 @@ $$ $$ \endtt prints -$$\adef~{\kern.5em } - \eqalignno{ - x + 2y + 3z &= 600 & \subeqmark a \cr - 12x + ~y - 3z &= -7 & \subeqmark b[label] \cr - 4x - ~y + 5z &= ~5 & \subeqmark c \cr +$$ \eqsystem[\eqskip=3pt]{ + x + 2y + 3z = 600 \toright{\subeqmark a}\cr + 12x + y - 3z = -7 \toright{\subeqmark b[label]}\cr + 4x - y + 5z = 5 \toright{\subeqmark c}\cr } $$ The equation~\ref[label] has negative right side. Moreover, it applies @@ -484,7 +637,57 @@ $$ $$ It looks better, doesn't it? -\sec Variables and digits from currently used text font +\sec `\bf` and `\bi` can do shapes with serifs + +\OpTeX/ sets `\bf` and `\bi` math selectors as sans serif, because this +follows the old traditional math typesetting of vectors and matrices. +But Knuth's \TeX/ has another default behavior:`\bf` and `\bi` select serifed +shaped. So, many people consider it as a standard. You can declare \^`\bfserif` if +you want serifed `\bf` and `\bi` math letters. + +\sec[rmchars] Selected upright letters and variants for Greek letters + +Some mathematicians claim that the letters $e$, $i$ and $\pi$ in meaning +\"a constant" should be printed in upright form. \TeX/ prints all variables in +math italic, but this package enables to set exceptions for some letters. +For example after \^`\rmchars``{e, i, \pi}`, all occurrences of these three letters +in math mode will be set in upright shape. If you set this, then the +well-known math identity `$e^{i\pi}=-1$` looks like this: +$$ + {\rm e}^{\rm i\muppi} = -1, \qquad \hbox{compare with:}\quad e^{i\pi} = -1. +$$ +The syntax is \^`\rmchars``{<list>}`, where <list> is a list of characters +separated by (optional) commas. The character is `a` to `z` or `A` to `Z` or +`\alpha` to `\omega`. + +If you set a character by `\rmchars` globally and you want to print it in italic +locally then use `\mit`, for example `{\mit e}` prints $e$. + +Several Greek letters have their variant shape: +`\epsilon`~$\epsilon$, `\varepsilon`~$\varepsilon$, +`\sigma`~$\sigma$, `\varsigma`~$\varsigma$, +`\phi`~$\phi$, `\varphi`~$\varphi$, +`\theta`~$\theta$, `\vartheta`~$\vartheta$, +`\pi`~$\pi$, `\varpi`~$\varpi$, +`\kappa`~$\kappa$, `\varkappa`~$\varkappa$, +`\rho`~$\rho$, `\varrho`~$\varrho$, +`\Theta`~$\Theta$, `\varTheta`~$\varTheta$. +Maybe, there is a tradition of usage variant shapes instead of standard ones +in your mathematics field. Then you can use +\^`\vargreek``{<list>}`, where <list> includes the list of no-var control +sequences for these letters (separated by optional comma). +For example `\vargreek{\epsilon \phi \rho}` causes that `\epsilon` is +printed as $\varepsilon$, `\phi` as $\varphi$ and `\rho` as $\varrho$. + +If you want to declare a Greek letter by both `\vargreek` and `\rmchars`, +use `\rmchars` first. + +The package provides two options `rmchars` and `vargreek`. The equation +sign must follow and then the `{<list>}` with syntax mentioned above. For example +`\mathset{vargreek={\epsilon,\rho}}`. + + +\sec[textvars] Variables and digits from currently used text font When Unicode math font is loaded then all variables and digits are printed from it in math mode. If you are using text fonts with another visual @@ -507,6 +710,12 @@ are use in the context \n`\left`, \n`\right`. These parentheses must be printed from math font always because text font is unable to create bigger versions of them. +The package provides the option `text={<list of words>}`, each <word> from the +<list> can be `digits` or `variables` or `moremath`. It runs corresponding macro(s) +described above. For example `\mathset{text=digits variables}` is equal to the +declaration of `\textdigits` `\textvariables`. + + \sec Replacing all missing math characters from another font If we load an additional math font by \o`\addUmathfont`, for example: @@ -541,7 +750,7 @@ This section has nothing common with the subject of this package but this packag can serve as inspiration for another package writers. It should be a template for another `<pkg>.opm` files. We emphasize several principles here. The basic information can be found in -\ulink[https://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf\#ref:prefixed] +\ulink[https://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf\#ref:basic-code] {section 2.2} of the \OpTeX/ manual. Try to run\fnote{Run it three times because Table of contents and Index are created.} \begtt @@ -573,7 +782,7 @@ The `\_<pkg>_version` macro should be declared here. The macro should expand to version number followed by version date. User can check the package version simply by expanding this macro after the package is loaded. And we want to have this data only at single place of the file. -You may check the log file if the text given by `\_codedecl` isn't too long +You may check the log file if the text given by \o`\_codedecl` isn't too long and isn't broken to more lines. Keeping single line is better because users can `grep @:` on log file in order to get information of all loaded packages and their version numbers. @@ -586,20 +795,25 @@ transformed to `\_<pkg>_foo` and by \o`\_endcode` which does \n`\endinput` when the macros are load. Final part of the file after \o`\_endcode` can include more detailed documentation. +If your package requires other packages then insert +\o`\load``[<package1>,<package2>]` after \o`\_codedecl` and before the the +\o`\_namespace` command. Each package uses its own namespace, so it is +important to load these packages before your \o`\_namespace` is opened. + If you have any idea of creating a macro package, you probably start with -experimental macros in user name space. It means that there are +experimental macros in the public namespace. It means that there are `\def\mymacro` etc. Once such a code is working, you can include it to the macro package introduced by \o`\_namespace``{<pkg>}`. You have to go through your code carefully sequence per sequence and insert `_` or `.` in front of -their name. The \"`_`" have to be used if the sequence is a primitive or -\OpTeX/ macro and the \"`.`" if it is your macro. So, the code fragment +their names. The \"`_`" prefix have to be used if the sequence is a primitive or +an \OpTeX/ macro and the \"`.`" prefix if it is your macro. So, the code fragment `\def\mymacro` have to be rewritten to `\_def\.mymacro`. If the macro -`\mymacro` is intended for usage in the user space, then append -`\_nspublic \mymacro ;` too. +`\mymacro` is intended for end users, then export it to the +public name space after it is defined by the \o`\_nspublic` `\mymacro ;` command. -Sometimes you may want to define a macro only for user space. Then -use prefix \O`\_newpublic` before your declaration, see declaration of - \^`\sgn` in this package as an exampe. The reason is: if +Sometimes you may want to define a macro only in public namespace. Then +use prefix \o`\_newpublic` before your declaration, see declaration of + \^`\sgn` in this package as an example. The reason is: if a user has defined such a macro already then the warning is printed. The user can read this warning and declare the macro after `\load[<pkg>]` in this case. @@ -616,9 +830,9 @@ The user can read this warning and declare the macro after \def\n`#1`{\exlink#1{\tnurl\#cs:}} \outlines 0 - \tit Macros for doing math more comfortable + \tit Macros for doing math more comfortably \hfill Version: \_math_version \par - \centerline{\it Petr Olšák\/\fnotemark1, 2022} + \centerline{\it Petr Olšák\/\fnotemark1, 2022, 2023} \fnotetext{\url{https://petr.olsak.net}} \notoc\nonum\sec Table of contents @@ -635,5 +849,15 @@ The user can read this warning and declare the macro after \endinput +0.08 2023-01-28: \eqsystem introduced, \eqfil added. +0.07 2023-01-23: \sgn etc. defined as \protected\def. + 2023-01-15: \replacemissingchars: bug fixed +0.06, 2023-01-14: \rmchars, \vargreek, \bfserif introduced +0.05, 2023-01-07: \mathset introduced +0.04, 2022-12-26: \casesof used in \.fparamA + \singlevert declared instead \_singlevert (bug fix) +0.03, 2022-12-19: \cotg, \arccotg defined, + \autop: \mathclose{} replaced by \bgroup...\egroup, + \scriptspaces: Rel-Op, Bin-Op spacing added. 0.02, 2022-11-26: \smartvert introduced 0.01, 2022-11-25: released diff --git a/macros/xetex/latex/xduts/xduts.dtx b/macros/xetex/latex/xduts/xduts.dtx index 3bb022f91e..8fed30fec7 100644 --- a/macros/xetex/latex/xduts/xduts.dtx +++ b/macros/xetex/latex/xduts/xduts.dtx @@ -1,7 +1,7 @@ % \iffalse %<*driver> \ProvidesFile{xduts.dtx} -[2023/02/06 v4.4.2.0 Xidian University TeX Suite] +[2023/02/09 v4.4.5.0 Xidian University TeX Suite] %</driver> %<class|sty>\NeedsTeXFormat{LaTeX2e} %<class|sty>\RequirePackage{expl3} @@ -9,7 +9,7 @@ %<xduugtp>\ProvidesExplClass{xduugtp} %<xdupgthesis>\ProvidesExplClass{xdupgthesis} %<xduugthesis>\ProvidesExplClass{xduugthesis} -%<class|sty> {2023/02/06}{4.4.2.0} +%<class|sty> {2023/02/09}{4.4.5.0} %<xdufont> {Xidian University Font package} %<xduugtp> {Xidian University Undergraduate Thesis Proposal class} %<xdupgthesis> {Xidian University Postgraduate Thesis document class} @@ -424,11 +424,12 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % 引用参考文献时,\tnx{cite}为上标样式,\tnx{parencite}为非上标样式。 % \subsection{参数设置} % \label{参数设置} +% \changes{v4.4.2.1}{2023/02/08}{修正接口文档说明样式} % \changes{v0.5.1.1}{2022/04/06}{增加xdusetup配置文档} % \changes{v1.30.0.1}{2022/06/20}{修改xdusetup配置文档} % \begin{function}[added=2022-03-07]{\xdusetup} % \begin{syntax} -% \tnx{xdusetup}=\argx{键值列表} +% \tn{xdusetup}\marg{键值列表} % \end{syntax} % \xduts{}提供了一系列选项,可自行配置。 % 载入文档类/宏包之后,以下所有选项均可通过统一的命令\tnx{xdusetup}来设置。 @@ -470,7 +471,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{字体选项} % \begin{function}[added=2022-03-06]{style/cjk-font} % \begin{syntax} -% \optx{style/cjk-font}=\metax{adobe|(fandol)|founder|sinotype|win|none} +% \opt{style/cjk-font} = adobe|(fandol)|founder|sinotype|win|none % \end{syntax} % 设置中文字体,具体配置见\tabrefx{tab:cjk-font}。 % \end{function} @@ -507,19 +508,19 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{table} % \begin{function}[added=2022-04-01]{style/cjk-fake-bold} % \begin{syntax} -% \optx{style/cjk-fake-bold}=\metax{伪粗体粗细程度} +% \opt{style/cjk-fake-bold} = \meta{伪粗体粗细程度} % \end{syntax} % 设置中文字体伪粗体粗细程度。默认为\valuex{3},对于部分存在对应粗体字体的中文字体,如FandolSong和FandolHei等,该选项不生效。 % \end{function} % \begin{function}[added=2022-04-01]{style/cjk-fake-slant} % \begin{syntax} -% \optx{style/cjk-fake-slant}=\metax{伪斜体倾斜程度} +% \opt{style/cjk-fake-slant} = \meta{伪斜体倾斜程度} % \end{syntax} % 设置中文字体伪斜体倾斜程度。默认为\valuex{0.2}。 % \end{function} % \begin{function}[added=2022-03-06,updated=2022-05-06]{style/latin-font} % \begin{syntax} -% \optx{style/latin-font}=\metax{tac|tacn|thcs|(gyre)|none} +% \opt{style/latin-font} = tac|tacn|thcs|(gyre)|none % \end{syntax} % 设置英文字体,具体配置见\tabrefx{tab:latin-font}。 % \end{function} @@ -550,8 +551,8 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{table} % \begin{function}[added=2023-01-28]{style/latin-sans-scale,style/latin-mono-scale} % \begin{syntax} -% \optx{style/latin-sans-scale}=\metax{upper|lower|(off)} -% \optx{style/latin-mono-scale}=\metax{upper|lower|(off)} +% \opt{style/latin-sans-scale} = upper|lower|(off) +% \opt{style/latin-mono-scale} = upper|lower|(off) % \end{syntax} % 匹配无衬线族和打字机族字符高度。 % \end{function} @@ -562,7 +563,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-03-06,updated=2022-03-09]{style/math-font} % \begin{syntax} -% \optx{style/math-font}=\metax{asana|cambria|(cm)|fira|garamond|lm|...|termes|xits|none} +% \opt{style/math-font} = asana|cambria|(cm)|fira|garamond|lm|...|termes|xits|none % \end{syntax} % 设置数学字体,具体配置见\tabrefx{tab:math-font}。除Computer Modern字体外,均使用\pkgx{unicode-math}宏包调用字体。 % \end{function} @@ -612,13 +613,13 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{tblr} % \begin{function}[added=2022-03-14]{style/unicode-math} % \begin{syntax} -% \optx{style/unicode-math}=\argx{unicode-math宏包选项} +% \opt{style/unicode-math} = \marg{unicode-math宏包选项} % \end{syntax} % 修改\pkgx{unicode-math}默认选项,具体配置参考\pkgx{unicode-math}宏包文档,仅在数学字体不为Computer Modern时有效。 % \end{function} % \begin{function}[added=2022-03-07]{style/font-type} % \begin{syntax} -% \optx{style/font-type}=\metax{(font)|file} +% \opt{style/font-type} = (font)|file % \end{syntax} % 设置字体调用方式。 % \end{function} @@ -628,7 +629,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-03-07]{style/font-path} % \begin{syntax} -% \optx{style/font-path}=\argx{路径} +% \opt{style/font-path} = \marg{路径} % \end{syntax} % 设置字体文件路径,即\metax{路径}目录内存储全部所需中文、英文和数学字体文件,仅在\optx{font-type}等于|file|时有效,默认值为\valuex{fonts}。 % \end{function} @@ -636,7 +637,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{英文字体} % \begin{function}[added=2022-04-01]{style/en-cjk-font} % \begin{syntax} -% \optx{style/en-cjk-font}=\metax{true|(false)} +% \opt{style/en-cjk-font} = true|(false) % \end{syntax} % 切换字体族时,英文是否使用中文字体。主要作用于封面、章节标题、caption、页眉页脚、参考文献列表等。 % \end{function} @@ -648,7 +649,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{标题数学字体配置} % \begin{function}[added=2023-02-03]{style/title-bold-math} % \begin{syntax} -% \optx{style/title-bold-math}=\metax{true|(false)} +% \opt{style/title-bold-math} = true|(false) % \end{syntax} % 是否自动加粗如下位置中的数学字体: % 中文研究生学位论文中,封面和提名页中英文标题,正文所有级别标题和目录一级标题; @@ -664,7 +665,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{语言配置} % \begin{function}[added=2022-03-29]{style/language} % \begin{syntax} -% \optx{style/language}=\metax{(zh)|en} +% \opt{style/language} = (zh)|en % \end{syntax} % 设置论文语言。 % \end{function} @@ -676,7 +677,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{参考文献配置} % \begin{function}[added=2022-04-02,updated=2022-04-03]{style/bib-backend} % \begin{syntax} -% \optx{style/bib-backend}=\metax{bibtex|(biblatex)} +% \opt{style/bib-backend} = bibtex|(biblatex) % \end{syntax} % 设置参考文献支持方式。 % \end{function} @@ -687,7 +688,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v1.31.0.0}{2022/06/21}{修改\pkgx{biblatex}默认选项} % \begin{function}[added=2022-06-21]{style/biblatex-option} % \begin{syntax} -% \optx{style/biblatex-option}=\argx{biblatex宏包选项} +% \opt{style/biblatex-option} = \marg{biblatex宏包选项} % \end{syntax} % 修改\pkgx{biblatex}默认选项,具体配置参考\filex{biblatex-gb7714-2015.pdf}, % 仅在\optx{style/bib-backend}等于|biblatex|时有效。例如: @@ -701,7 +702,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{页面配置} % \begin{function}[added=2022-04-12]{style/symmetric-margin} % \begin{syntax} -% \optx{style/symmetric-margin}=\metax{true|(false)} +% \opt{style/symmetric-margin} = true|(false) % \end{syntax} % 设置左右页边距是否对称。 % \end{function} @@ -711,7 +712,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-05-08]{style/page-vertical-align} % \begin{syntax} -% \optx{style/page-vertical-align}=\metax{分散对齐|(顶部对齐)} +% \opt{style/page-vertical-align} = 分散对齐|(顶部对齐) % \end{syntax} % 设置页面垂直方向的对齐方式。 % \end{function} @@ -723,7 +724,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{文件配置} % \begin{function}[added=2022-07-01]{style/file-search-path} % \begin{syntax} -% \optx{style/file-search-path}=\argx{路径} +% \opt{style/file-search-path} = \marg{路径} % \end{syntax} % 设置文件搜索路径,可用于\tnx{input}、\tnx{include}和\tnx{includegraphics}, % 多个路径之间需要使用英文半角逗号隔开。 @@ -731,9 +732,9 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{function} % \begin{function}[added=2022-07-01]{style/fix-input,style/fix-include,style/fix-includegraphics} % \begin{syntax} -% \optx{style/fix-input}=\metax{true|(false)} -% \optx{style/fix-include}=\metax{true|(false)} -% \optx{style/fix-includegraphics}=\metax{true|(false)} +% \opt{style/fix-input} = true|(false) +% \opt{style/fix-include} = true|(false) +% \opt{style/fix-includegraphics} = true|(false) % \end{syntax} % TEXMF树搜索优先级高于用户自定义的文件搜索路径, % 如果在TEXMF树内存在同名文件,则会导致错误的文件被加载。 @@ -744,7 +745,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{交叉引用配置} % \begin{function}[added=2022-04-16,updated=2022-05-08]{style/ref-add-space} % \begin{syntax} -% \optx{style/ref-add-space}=\metax{true|(false)} +% \opt{style/ref-add-space} = true|(false) % \end{syntax} % 是否自动调整\tnx{ref}和\tnx{pageref}两侧中英文间空白。 % \end{function} @@ -760,7 +761,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v1.0.0.0}{2022/04/14}{设置图、表、算法标签与后面标题之间的间距} % \begin{function}[added=2022-04-14]{style/caption-label-sep} % \begin{syntax} -% \optx{style/caption-label-sep}=\argx{间距} +% \opt{style/caption-label-sep} = \meta{间距} % \end{syntax} % 设置图、表、算法标签与后面标题之间的间距,默认值为\valuex{0.75em}。 % \end{function} @@ -769,7 +770,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v3.0.0.0}{2022/12/03}{设置图表caption格式} % \begin{function}[added=2022-12-03]{style/ft-caption-format} % \begin{syntax} -% \optx{style/ft-caption-format}=\metax{plain|(hang)} +% \opt{style/ft-caption-format} = plain|(hang) % \end{syntax} % 设置图表caption格式。 % \begin{optdesc} @@ -780,7 +781,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v3.0.0.0}{2022/12/03}{设置图表caption对齐方式} % \begin{function}[added=2022-12-03]{style/ft-caption-align} % \begin{syntax} -% \optx{style/ft-caption-align}=\metax{left|centering|(centering-left)} +% \opt{style/ft-caption-align} = left|centering|(centering-left) % \end{syntax} % 设置图表caption对齐方式。 % \begin{optdesc} @@ -792,7 +793,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v0.10.0.1}{2022/04/13}{补充表格内容字号文档说明} % \begin{function}[added=2022-04-13,updated=2022-04-15]{style/table-small-font} % \begin{syntax} -% \optx{style/table-small-font}=\metax{(true)|false} +% \opt{style/table-small-font} = (true)|false % \end{syntax} % 设置表格内容字号是否为五号。 % \end{function} @@ -804,7 +805,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{算法配置} % \begin{function}[added=2022-06-25]{style/algorithm-small-caption} % \begin{syntax} -% \optx{style/algorithm-small-caption}=\metax{(true)|false} +% \opt{style/algorithm-small-caption} = (true)|false % \end{syntax} % 设置算法caption字号是否为五号。 % \end{function} @@ -814,7 +815,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-04-15]{style/algorithm-small-font} % \begin{syntax} -% \optx{style/algorithm-small-font}=\metax{(true)|false} +% \opt{style/algorithm-small-font} = (true)|false % \end{syntax} % 设置算法内容字号是否为五号。 % \end{function} @@ -825,7 +826,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v3.0.0.0}{2022/12/03}{设置算法caption格式} % \begin{function}[added=2022-12-03]{style/alg-caption-format} % \begin{syntax} -% \optx{style/alg-caption-format}=\metax{plain|(hang)} +% \opt{style/alg-caption-format} = plain|(hang) % \end{syntax} % 设置算法caption格式。 % \begin{optdesc} @@ -836,7 +837,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v3.0.0.0}{2022/12/03}{设置算法caption对齐方式} % \begin{function}[added=2022-12-03]{style/alg-caption-align} % \begin{syntax} -% \optx{style/alg-caption-align}=\metax{(left)|centering|centering-left} +% \opt{style/alg-caption-align} = (left)|centering|centering-left % \end{syntax} % 设置算法caption对齐方式。 % \begin{optdesc} @@ -848,7 +849,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v3.1.0.0}{2022/12/03}{设置算法三线间距} % \begin{function}[added=2022-12-03]{style/add-alg-rule-vspace} % \begin{syntax} -% \optx{style/add-alg-rule-vspace}=\metax{true|(false)} +% \opt{style/add-alg-rule-vspace} = true|(false) % \end{syntax} % 设置是否为ruled样式的算法环境的三条横线增加纵向间距。 % \begin{optdesc} @@ -860,13 +861,13 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{章节配置} % \begin{function}[added=2022-04-05]{style/before-skip} % \begin{syntax} -% \optx{style/before-skip}=\argx{间距列表} +% \opt{style/before-skip} = \marg{间距列表} % \end{syntax} % 设置章节标题前的垂直间距,默认值为\valuex{\{24pt, 18pt, 12pt, 12pt, 12pt, 12pt\}},分别对应\tnx{chapter}、\tnx{section}、\tnx{subsection}、\tnx{subsubsection}、\tnx{paragraph}和\tnx{subparagraph}。 % \end{function} % \begin{function}[added=2022-04-05]{style/after-skip} % \begin{syntax} -% \optx{style/after-skip}=\argx{间距列表} +% \opt{style/after-skip} = \marg{间距列表} % \end{syntax} % 设置章节标题后的垂直间距,默认值为\valuex{\{18pt, 12pt, 6pt, 6pt, 6pt, 6pt\}},分别对应\tnx{chapter}、\tnx{section}、\tnx{subsection}、\tnx{subsubsection}、\tnx{paragraph}和\tnx{subparagraph}。 % \end{function} @@ -880,12 +881,12 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % style/subpara-zihao % } % \begin{syntax} -% \optx{style/chap-zihao}=\metax{0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8} -% \optx{style/sec-zihao}=\metax{0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8} -% \optx{style/subsec-zihao}=\metax{0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8} -% \optx{style/subsubsec-zihao}=\metax{0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8} -% \optx{style/para-zihao}=\metax{0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8} -% \optx{style/subpara-zihao}=\metax{0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8} +% \opt{style/chap-zihao} = 0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8 +% \opt{style/sec-zihao} = 0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8 +% \opt{style/subsec-zihao} = 0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8 +% \opt{style/subsubsec-zihao} = 0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8 +% \opt{style/para-zihao} = 0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8 +% \opt{style/subpara-zihao} = 0|-0|1|-1|2|-2|3|-3|4|-4|5|-5|6|-6|7|8 % \end{syntax} % 设置章节标题字号。 % 当论文语言为中文时,默认值分别为\valuex{3}、\valuex{4}、\valuex{4}、\valuex{4}、\valuex{4}、\valuex{4}。 @@ -913,8 +914,8 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \label{对照表配置} % \begin{function}[added=2022-06-05]{style/customize-los,style/customize-loa} % \begin{syntax} -% \optx{style/customize-los}=\metax{(true)|false} -% \optx{style/customize-loa}=\metax{(true)|false} +% \opt{style/customize-los} = (true)|false +% \opt{style/customize-loa} = (true)|false % \end{syntax} % 是否完全自定义符号对照表和缩略语对照表。 % \end{function} @@ -939,8 +940,8 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v2.10.2.1}{2022/06/28}{修改对照表默认列格式} % \begin{function}[added=2022-06-05,updated=2022-06-28]{style/colspec-los,style/colspec-loa} % \begin{syntax} -% \optx{style/colspec-los}=\argx{符号对照表列格式} -% \optx{style/colspec-loa}=\argx{缩略语对照表列格式} +% \opt{style/colspec-los} = \marg{符号对照表列格式} +% \opt{style/colspec-loa} = \marg{缩略语对照表列格式} % \end{syntax} % 设置符号对照表和缩略语对照表列格式, % 符号对照表列格式默认值为\valuex{Q[l,h]X[l,h]}。 @@ -950,8 +951,8 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{function} % \begin{function}[added=2022-06-05]{style/title-row-los,style/title-row-loa} % \begin{syntax} -% \optx{style/title-row-los}=\metax{true|(false)} -% \optx{style/title-row-loa}=\metax{true|(false)} +% \opt{style/title-row-los} = true|(false) +% \opt{style/title-row-loa} = true|(false) % \end{syntax} % 是否每页均显示符号对照表和缩略语对照表标题行。 % 仅在\optx{style/customize-los}和\optx{style/customize-loa}等于\valuex{false}时有效。 @@ -966,8 +967,8 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v1.28.4.1}{2022/06/19}{修正作者简介示例} % \begin{function}[added=2022-06-07]{style/customize-edubg,style/customize-resresult} % \begin{syntax} -% \optx{style/customize-edubg}=\metax{(true)|false} -% \optx{style/customize-resresult}=\metax{(true)|false} +% \opt{style/customize-edubg} = (true)|false +% \opt{style/customize-resresult} = (true)|false % \end{syntax} % 是否完全自定义作者简介中教育背景和攻读硕士学位期间的研究成果。 % \end{function} @@ -1105,7 +1106,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v1.9.0.0}{2022/05/03}{增加研究生信息录入选项文档} % \begin{function}[added=2022-05-02,updated=2022-05-03]{info/graduate-type} % \begin{syntax} -% \optx{info/graduate-type}=\metax{(硕士)|博士} +% \opt{info/graduate-type} = (硕士)|博士 % \end{syntax} % 设置研究生类型。 % \end{function} @@ -1115,7 +1116,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-05-03]{info/degree-type} % \begin{syntax} -% \optx{info/degree-type}=\metax{(学术)|专业} +% \opt{info/degree-type} = (学术)|专业 % \end{syntax} % 设置研究生学位类型。 % \end{function} @@ -1125,146 +1126,146 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-05-03]{info/degree,info/degree*} % \begin{syntax} -% \optx{info/degree}=\argx{研究生学位类别中文名称} -% \optx{info/degree*}=\argx{研究生学位类别英文名称} +% \opt{info/degree} = \meta{研究生学位类别中文名称} +% \opt{info/degree*} = \meta{研究生学位类别英文名称} % \end{syntax} % 设置研究生学位类别。 % \end{function} % \begin{function}[added=2022-04-01,updated=2022-05-30]{info/title,info/title*} % \begin{syntax} -% \optx{info/title}=\argx{论文中文标题} -% \optx{info/title*}=\argx{论文英文标题} +% \opt{info/title} = \meta{论文中文标题} +% \opt{info/title*} = \meta{论文英文标题} % \end{syntax} % 设置论文标题。建议使用换行控制符(|\\|)手动制定换行位点, % 本科毕业设计论文最多两行,研究生学位论文无限制。 % \end{function} % \begin{function}[added=2022-04-01]{info/department} % \begin{syntax} -% \optx{info/department}=\argx{院系名称} +% \opt{info/department} = \meta{院系名称} % \end{syntax} % 设置院系名称。 % \end{function} % \begin{function}[added=2022-04-01,updated=2022-05-03]{info/major,info/major*} % \begin{syntax} -% \optx{info/major}=\argx{专业名称/一级学科名称} -% \optx{info/major*}=\argx{一级学科英文名称} +% \opt{info/major} = \meta{专业名称/一级学科名称} +% \opt{info/major*} = \meta{一级学科英文名称} % \end{syntax} % 设置专业名称/一级学科名称。 % \end{function} % \begin{function}[added=2022-05-03]{info/sub-major} % \begin{syntax} -% \optx{info/sub-major}=\argx{二级学科名称} +% \opt{info/sub-major} = \meta{二级学科名称} % \end{syntax} % 设置二级学科名称。 % \end{function} % \begin{function}[added=2022-05-03]{info/domain} % \begin{syntax} -% \optx{info/domain}=\argx{领域} +% \opt{info/domain} = \meta{领域} % \end{syntax} % 设置领域名称。 % \end{function} % \begin{function}[added=2022-04-01,updated=2022-05-03]{info/author,info/author*} % \begin{syntax} -% \optx{info/author}=\argx{作者姓名} -% \optx{info/author*}=\argx{作者姓名拼音} +% \opt{info/author} = \meta{作者姓名} +% \opt{info/author*} = \meta{作者姓名拼音} % \end{syntax} % 设置作者姓名。 % \end{function} % \begin{function}[added=2022-04-01,updated=2022-05-03]{info/supervisor,info/supervisor*} % \begin{syntax} -% \optx{info/supervisor}=\argx{导师姓名} -% \optx{info/supervisor*}=\argx{导师姓名拼音} +% \opt{info/supervisor} = \meta{导师姓名} +% \opt{info/supervisor*} = \meta{导师姓名拼音} % \end{syntax} % 设置导师姓名。 % \end{function} % \begin{function}[added=2022-04-01]{info/supervisor-department} % \begin{syntax} -% \optx{info/supervisor-department}=\argx{院内导师姓名} +% \opt{info/supervisor-department} = \meta{院内导师姓名} % \end{syntax} % 设置院内导师姓名。 % \end{function} % \begin{function}[added=2022-04-01,updated=2022-05-03]{info/supervisor-enterprise,info/supervisor-enterprise*} % \begin{syntax} -% \optx{info/supervisor-enterprise}=\argx{校外导师姓名} -% \optx{info/supervisor-enterprise*}=\argx{校外导师姓名拼音} +% \opt{info/supervisor-enterprise} = \meta{校外导师姓名} +% \opt{info/supervisor-enterprise*} = \meta{校外导师姓名拼音} % \end{syntax} % 设置校外导师姓名。 % \end{function} % \begin{function}[added=2022-04-01]{info/supervisor-school} % \begin{syntax} -% \optx{info/supervisor-school}=\argx{校内导师姓名} +% \opt{info/supervisor-school} = \meta{校内导师姓名} % \end{syntax} % 设置校内导师姓名。 % \end{function} % \begin{function}[added=2022-05-03]{info/supervisor-title,info/supervisor-title*} % \begin{syntax} -% \optx{info/supervisor-title}=\argx{导师职称} -% \optx{info/supervisor-title*}=\argx{导师职称英文名称} +% \opt{info/supervisor-title} = \meta{导师职称} +% \opt{info/supervisor-title*} = \meta{导师职称英文名称} % \end{syntax} % 设置导师职称。 % \end{function} % \begin{function}[added=2022-05-03]{info/supervisor-enterprise-title,info/supervisor-enterprise-title*} % \begin{syntax} -% \optx{info/supervisor-enterprise-title}=\argx{校外导师职称} -% \optx{info/supervisor-enterprise-title*}=\argx{校外导师职称英文名称} +% \opt{info/supervisor-enterprise-title} = \meta{校外导师职称} +% \opt{info/supervisor-enterprise-title*} = \meta{校外导师职称英文名称} % \end{syntax} % 设置校外导师职称。 % \end{function} % \begin{function}[added=2022-12-31]{info/class} % \begin{syntax} -% \optx{info/class}=\argx{界} +% \opt{info/class} = \meta{界} % \end{syntax} % 设置界,即毕业年份。 % \end{function} % \begin{function}[added=2022-04-01]{info/class-id} % \begin{syntax} -% \optx{info/class-id}=\argx{作者班级号} +% \opt{info/class-id} = \meta{作者班级号} % \end{syntax} % 设置作者班级号。 % \end{function} % \begin{function}[added=2022-04-01]{info/student-id} % \begin{syntax} -% \optx{info/student-id}=\argx{作者学号} +% \opt{info/student-id} = \meta{作者学号} % \end{syntax} % 设置作者学号。 % \end{function} % \begin{function}[added=2022-05-03]{info/clc} % \begin{syntax} -% \optx{info/clc}=\argx{中图分类号} +% \opt{info/clc} = \meta{中图分类号} % \end{syntax} % 设置中图分类号。 % \end{function} % \begin{function}[added=2022-05-03]{info/secret-level} % \begin{syntax} -% \optx{info/secret-level}=\metax{秘密|(公开)} +% \opt{info/secret-level} = 秘密|(公开) % \end{syntax} % 设置密级。 % \end{function} % \begin{function}[added=2022-05-30]{info/secret-year} % \begin{syntax} -% \optx{info/secret-year}=\argx{保密年限} +% \opt{info/secret-year} = \meta{保密年限} % \end{syntax} % 设置保密年限,仅在\optx{secret-level}等于|秘密|时有效。 % \end{function} % \changes{v1.17.0.1}{2022/05/29}{研究生学位论文提交日期格式} % \begin{function}[added=2022-05-03,updated=2022-12-31]{info/submit-date} % \begin{syntax} -% \optx{info/submit-date}=\argx{yyyy-mm} -% \optx{info/submit-date}=\argx{yyyy-mm-dd} +% \opt{info/submit-date} = \meta{yyyy-mm} +% \opt{info/submit-date} = \meta{yyyy-mm-dd} % \end{syntax} % 设置提交日期,如果留空,则自动使用编译当天日期。 % \end{function} % \changes{v2.1.0.0}{2022/06/22}{声明页扫描文件路径} % \begin{function}[added=2022-06-22]{info/statement-scan} % \begin{syntax} -% \optx{info/statement-scan}=\argx{学位论文独创性声明和关于论文使用授权的说明页扫描文件路径} +% \opt{info/statement-scan} = \marg{学位论文独创性声明和关于论文使用授权的说明页扫描文件路径} % \end{syntax} % 设置学位论文独创性声明和关于论文使用授权的说明页扫描文件路径。 % \end{function} % \changes{v2.2.0.0}{2022/06/23}{声明页签名文件路径} % \begin{function}[added=2022-06-23]{info/statement-sign} % \begin{syntax} -% \optx{info/statement-sign}=\argx{文件路径1,文件路径2,文件路径3,文件路径4,文件路径5,文件路径6} +% \opt{info/statement-sign} = \marg{文件路径1,文件路径2,文件路径3,文件路径4,文件路径5,文件路径6} % \end{syntax} % 设置声明页签名文件路径。 % 文件支持格式与\tnx{includegraphics}一致,建议文件为透明背景且仅有黑色,并尽量减少边距。 @@ -1279,7 +1280,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-12-31]{info/sign} % \begin{syntax} -% \optx{info/sign}=\argx{文件路径1,文件路径2} +% \opt{info/sign} = \marg{文件路径1,文件路径2} % \end{syntax} % 设置开题报告签名文件路径。 % 文件支持格式与\tnx{includegraphics}一致,建议文件为透明背景且仅有黑色,并尽量减少边距。 @@ -1290,7 +1291,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-12-31]{info/date} % \begin{syntax} -% \optx{info/date}=\argx{日期1,日期2} +% \opt{info/date} = \marg{日期1,日期2} % \end{syntax} % 设置开题报告签名日期,格式为\argx{yyyy-mm-dd},如果留空,则自动使用编译当天日期。 % \end{function} @@ -1300,55 +1301,55 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-04-02]{info/abstract,info/abstract*} % \begin{syntax} -% \optx{info/abstract}=\argx{中文摘要文件路径} -% \optx{info/abstract*}=\argx{英文摘要文件路径} +% \opt{info/abstract} = \marg{中文摘要文件路径} +% \opt{info/abstract*} = \marg{英文摘要文件路径} % \end{syntax} % 设置摘要文件路径,相应文件内仅撰写摘要内容,无需任何环境。 % \end{function} % \begin{function}[added=2022-04-02]{info/keywords,info/keywords*} % \begin{syntax} -% \optx{info/keywords}=\argx{中文关键词} -% \optx{info/keywords*}=\argx{英文关键词} +% \opt{info/keywords} = \marg{中文关键词} +% \opt{info/keywords*} = \marg{英文关键词} % \end{syntax} % 设置关键词,关键词之间需要使用英文半角逗号隔开。 % \end{function} % \changes{v1.22.0.0}{2022/06/05}{符号对照表文件路径} % \begin{function}[added=2022-06-05]{info/los} % \begin{syntax} -% \optx{info/los}=\argx{符号对照表文件路径} +% \opt{info/los} = \marg{符号对照表文件路径} % \end{syntax} % 设置符号对照表文件路径。 % \end{function} % \changes{v1.22.0.0}{2022/06/05}{缩略语对照表文件路径} % \begin{function}[added=2022-06-05]{info/loa} % \begin{syntax} -% \optx{info/loa}=\argx{缩略语对照表文件路径} +% \opt{info/loa} = \marg{缩略语对照表文件路径} % \end{syntax} % 设置缩略语对照表文件路径。 % \end{function} % \changes{v2.0.0.0}{2022/06/21}{修改参考文献文件路径选项名称} % \begin{function}[added=2022-06-21]{info/bib-resource} % \begin{syntax} -% \optx{info/bib-resource}=\argx{参考文献文件路径} +% \opt{info/bib-resource} = \marg{参考文献文件路径} % \end{syntax} % 设置参考文献\filex{.bib}文件路径,多个文件之间需要使用英文半角逗号隔开。 % \end{function} % \changes{v4.0.0.0}{2022/12/11}{增加附录文件接口} % \begin{function}[added=2022-12-11]{info/appendix} % \begin{syntax} -% \optx{info/appendix}=\argx{附录文件路径} +% \opt{info/appendix} = \marg{附录文件路径} % \end{syntax} % 设置附录文件路径,多个文件之间需要使用英文半角逗号隔开。 % \end{function} % \begin{function}[added=2022-04-02]{info/acknowledgements} % \begin{syntax} -% \optx{info/acknowledgements}=\argx{致谢文件路径} +% \opt{info/acknowledgements} = \marg{致谢文件路径} % \end{syntax} % 设置致谢文件路径,相应文件内仅撰写致谢内容,无需任何环境。 % \end{function} % \begin{function}[added=2022-06-07]{info/bio} % \begin{syntax} -% \optx{info/bio}=\argx{作者简介路径} +% \opt{info/bio} = \marg{作者简介路径} % \end{syntax} % 设置作者简介文件路径,文件内容可参考\secrefx{作者简介配置}中的示例。 % \end{function} @@ -1621,7 +1622,7 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \changes{v2.12.1.0}{2022/07/03}{页面和信息移除选项增加分组} % \begin{function}[added=2022-06-26]{style/remove-page} % \begin{syntax} -% \optx{style/remove-page}=\argx{封面|提名页|声明页|摘要|索引|对照表|目录|附录|参考文献|致谢|作者简介} +% \opt{style/remove-page} = \marg{封面|提名页|声明页|摘要|索引|对照表|目录|附录|参考文献|致谢|作者简介} % \end{syntax} % 设置移除的页面,可多选,多个值之间需要使用英文半角逗号隔开。 % \end{function} @@ -1633,19 +1634,19 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} % \end{optdesc} % \begin{function}[added=2022-06-26]{style/remove-header} % \begin{syntax} -% \optx{style/remove-header}=\metax{true|(false)} +% \opt{style/remove-header} = true|(false) % \end{syntax} % 设置是否移除页眉。 % \end{function} % \begin{function}[added=2022-06-26]{style/remove-footer} % \begin{syntax} -% \optx{style/remove-footer}=\metax{true|(false)} +% \opt{style/remove-footer} = true|(false) % \end{syntax} % 设置是否移除页脚。 % \end{function} % \begin{function}[added=2022-06-26]{style/anonymous} % \begin{syntax} -% \optx{anonymous}=\metax{true|(false)} +% \opt{anonymous} = true|(false) % \end{syntax} % 设置是否开启匿名,与\secrefx{额外命令}中的\tnx{anon}搭配使用。 % \end{function} @@ -4050,11 +4051,15 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} \cs_generate_variant:Nn \@@_get_text_width:Nn { NV } % \end{macrocode} % \end{macro} +% \changes{v4.4.5.0}{2023/02/09}{修复书签中目录跳转异常} % \begin{macro}{\@@_add_bookmark:n} % 为当前位置添加书签。 % \begin{macrocode} \cs_new:Npn \@@_add_bookmark:n #1 - { \currentpdfbookmark { #1 } { #1 } } + { + \cleardoublepage + \currentpdfbookmark { #1 } { #1 } + } % \end{macrocode} % \end{macro} % \begin{macro}{\@@_add_toc:n} @@ -5619,34 +5624,38 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} \cs_set_eq:NN \SlashFont \rmfamily } % \end{macrocode} +% \bibtex{}和\pkgx{biblatex}通用字体字号配置。 +% \begin{macrocode} + \cs_set:Npn \bibfont + { +%<xdupgthesis> \rmfamily +%<xduugthesis> \@@_rm_family: +%<thesis> \zihao { 5 } +%<tp> \zihao { -4 } +%<xdupgthesis> \dim_set:Nn \baselineskip { 20pt } + } + } +% \end{macrocode} % \begin{macrocode} %<*xdupgthesis> % \end{macrocode} +% \changes{v4.4.4.0}{2023/02/09}{精简研究生学位论文移除参考文献列表宏包调用} % \changes{v2.12.2.0}{2022/08/15}{修正本科毕业设计参考文献列表编译错误} % \changes{v2.7.0.0}{2022/06/26}{\bibtex{}下允许不生成文献列表} % \bibtex{}下允许不生成文献列表。 % \begin{macrocode} \ctex_at_end_preamble:n { - \bool_if:NT \l_@@_rm_ref_bool - { \RequirePackage { bibentry } } + \tl_if_eq:NnT \l_@@_bib_tool_tl { bibtex } + { + \bool_if:NT \l_@@_rm_ref_bool + { \RequirePackage { bibentry } } + } } % \end{macrocode} % \begin{macrocode} %</xdupgthesis> % \end{macrocode} -% \bibtex{}和\pkgx{biblatex}通用字体字号配置。 -% \begin{macrocode} - \cs_set:Npn \bibfont - { -%<xdupgthesis> \rmfamily -%<xduugthesis> \@@_rm_family: -%<thesis> \zihao { 5 } -%<tp> \zihao { -4 } -%<xdupgthesis> \dim_set:Nn \baselineskip { 20pt } - } - } -% \end{macrocode} % \end{macro} % \begin{macrocode} %</thesis|tp> @@ -5832,7 +5841,6 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} \loadgeometry { cover } \pagestyle { empty } \dim_set:Nn \parindent { 0pt } - \@@_add_bookmark:n { \@@_lang_switch:nn { 封面 } { Cover } } % \end{macrocode} % 排版班级和学号。 % \begin{macrocode} @@ -7131,7 +7139,6 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} \dim_set:Nn \baselineskip { 20pt } \bool_if:NF \l_@@_rm_cover_bool { - \@@_add_bookmark:n { \@@_lang_switch:nn { 封面 } { Cover } } % \end{macrocode} % \changes{v4.4.0.0}{2023/02/03}{研究生封面标题中数学字体加粗} % \changes{v1.18.1.0}{2022/05/30}{不拆分研究生封面标题} @@ -7528,12 +7535,13 @@ literate = {\$}{{\textcolor{purple3}{\$}}}{1} subsection / format = { \rmfamily \zihao { 4 } \bfseries \raggedright }, subsection / indent = { \l_@@_bio_indent_dim } } - \setcounter { section } { 0 } - \addtocontents { toc } { \protect \setcounter { tocdepth } { 0 } } % \end{macrocode} +% \changes{v4.4.3.0}{2023/02/09}{修复研究生学位论文书签深度} % 作者简介文件。 % \begin{macrocode} + \addtocontents { toc } { \protect \setcounter { tocdepth } { 0 } } \file_if_exist_input:n { \l_@@_bio_str } + \addtocontents { toc } { \protect \setcounter { tocdepth } { 2 } } \group_end: } } diff --git a/macros/xetex/latex/xduts/xduts.pdf b/macros/xetex/latex/xduts/xduts.pdf Binary files differindex 224504c986..92479c283e 100644 --- a/macros/xetex/latex/xduts/xduts.pdf +++ b/macros/xetex/latex/xduts/xduts.pdf |