Skip to content

Commit

Permalink
Merge branch 'master' into fix-math-fraction-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 29, 2024
2 parents 1c009c7 + 0cd24ab commit bd2dd1a
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ max_line_length = 120

# StyLua keys
collapse_simple_statement = never
space_after_functions = definitions
space_after_function_names = definitions

# EmmyLuaCodeStyle keys
continuation_indent = 6
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,18 @@ If you install LuaRocks for use with SILE via `pacman`, use the `lua51-*` varian

#### Fedora

A [COPR][copr] repository is available for Fedora users with packages of SILE and all the necessary dependencies.
Fedora 38 and later are supported.
There is work in progress to get the packages added to the official Fedora repository.
Fedora Linux has SILE in their official repositories. To install run:

```console
$ dnf copr enable jonny/SILE
$ dnf install sile
```

Not all the fonts are not installed by default, to install them:

```console
$ dnf install sil-gentium-plus-fonts alerque-libertinus-fonts hack-fonts
```

#### OpenSUSE

OpenSUSE has official packages ready to install the usual way:
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ AM_COND_IF([SYSTEM_LIBTEXPDF],
[AC_MSG_FAILURE([--with-system-libtexpdf was given, but test for libtexpdf failed])])],
[AC_CONFIG_SUBDIRS([libtexpdf])])

PKG_CHECK_MODULES(ICU, icu-uc icu-io, [
PKG_CHECK_MODULES(ICU, icu-uc icu-i18n icu-io, [
with_icu=yes
],[
AC_CHECK_TOOL(ICU_CONFIG, icu-config, no)
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/math/base-elements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,8 @@ end

function elements.text:_init (kind, attributes, script, text)
elements.terminal._init(self)
if not (kind == "number" or kind == "identifier" or kind == "operator") then
SU.error("Unknown text node kind '" .. kind .. "'; should be one of: number, identifier, operator")
if not (kind == "number" or kind == "identifier" or kind == "operator" or kind == "string") then
SU.error("Unknown text node kind '" .. kind .. "'; should be one of: number, identifier, operator, string")
end
self.kind = kind
self.script = script
Expand Down
58 changes: 46 additions & 12 deletions packages/math/texlike.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ local mathGrammar = function (_ENV)
return ret
end
local group = P"{" * V"mathlist" * (P"}" + E("`}` expected"))
-- Simple amsmath-like \text command (no embedded math)
local textgroup = P"{" * C((1-P"}")^1) * (P"}" + E("`}` expected"))
local element_no_infix =
V"def" +
V"text" + -- Important: before command
V"command" +
group +
V"argument" +
Expand Down Expand Up @@ -115,6 +118,11 @@ local mathGrammar = function (_ENV)
sub = element_no_infix * _ * P"_" * _ * element_no_infix
atom = natural + C(utf8code - S"\\{}%^_&") +
(P"\\{" + P"\\}") / function (s) return string.sub(s, -1) end
text = (
P"\\text" *
Cg(parameters, "options") *
textgroup
)
command = (
P"\\" *
Cg(ctrl_sequence_name, "command") *
Expand Down Expand Up @@ -252,6 +260,23 @@ local compileToStr = function (argEnv, mathlist)
end
end

local function isBigOperator (tree)
if tree.command ~= "mo" then
return false
end
-- Case \mo[atom=big]{ops}
-- E.g. \mo[atom=big]{lim}
if tree.options and tree.options.atom == "big" then
return true
end
-- Case \mo{ops} where ops is registered as big operator (unicode-symbols)
-- E.g. \mo{∑) or \sum
if tree[1] and symbolDefaults[tree[1]] and symbolDefaults[tree[1]].atom == atomType.bigOperator then
return true
end
return false
end

local function compileToMathML_aux (_, arg_env, tree)
if type(tree) == "string" then
return tree
Expand Down Expand Up @@ -328,21 +353,13 @@ local function compileToMathML_aux (_, arg_env, tree)
tree.options = {}
-- Translate TeX-like sub/superscripts to `munderover` or `msubsup`,
-- depending on whether the base is a big operator
elseif tree.id == "sup" and tree[1].command == "mo" and tree[1].atom == atomType.bigOperator then
elseif tree.id == "sup" and isBigOperator(tree[1]) then
tree.command = "mover"
elseif tree.id == "sub" and tree[1].command == "mo" and symbolDefaults[tree[1][1]].atom == atomType.bigOperator then
elseif tree.id == "sub" and isBigOperator(tree[1]) then
tree.command = "munder"
elseif
tree.id == "subsup"
and tree[1].command == "mo"
and symbolDefaults[tree[1][1]].atom == atomType.bigOperator
then
elseif tree.id == "subsup" and isBigOperator(tree[1]) then
tree.command = "munderover"
elseif
tree.id == "supsub"
and tree[1].command == "mo"
and symbolDefaults[tree[1][1]].atom == atomType.bigOperator
then
elseif tree.id == "supsub" and isBigOperator(tree[1]) then
tree.command = "munderover"
local tmp = tree[2]
tree[2] = tree[3]
Expand All @@ -365,6 +382,8 @@ local function compileToMathML_aux (_, arg_env, tree)
return compileToMathML_aux(nil, compiledArgs, tree[1])
end)
return nil
elseif tree.id == "text" then
tree.command = "mtext"
elseif tree.id == "command" and commands[tree.command] then
local argTypes = commands[tree.command][1]
local cmdFun = commands[tree.command][2]
Expand Down Expand Up @@ -480,6 +499,21 @@ compileToMathML(
\def{bi}{\mi[mathvariant=bold-italic]{#1}}
\def{dsi}{\mi[mathvariant=double-struck]{#1}}
\def{lim}{\mo[atom=big]{lim}}
% From amsmath:
\def{to}{\mo[atom=bin]{→}}
\def{gcd}{\mo[atom=big]{gcd}}
\def{sup}{\mo[atom=big]{sup}}
\def{inf}{\mo[atom=big]{inf}}
\def{max}{\mo[atom=big]{max}}
\def{min}{\mo[atom=big]{min}}
% Those use U+202F NARROW NO-BREAK SPACE in their names
\def{limsup}{\mo[atom=big]{lim sup}}
\def{liminf}{\mo[atom=big]{lim inf}}
\def{projlim}{\mo[atom=big]{proj lim}}
\def{injlim}{\mo[atom=big]{inj lim}}
% Standard spaces gleaned from plain TeX
\def{thinspace}{\mspace[width=thin]}
\def{negthinspace}{\mspace[width=-thin]}
Expand Down
19 changes: 16 additions & 3 deletions packages/math/typesetter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ConvertMathML (_, content)
local script = content.options.mathvariant and b.mathVariantToScriptType(content.options.mathvariant)
local text = content[1]
if type(text) ~= "string" then
SU.error("mi command contains " .. text .. ", which is not text")
SU.error("mi command contains content which is not text")
end
script = script or (luautf8.len(text) == 1 and b.scriptType.italic or b.scriptType.upright)
return b.text("identifier", {}, script, text)
Expand All @@ -67,15 +67,15 @@ function ConvertMathML (_, content)
end
end
if type(text) ~= "string" then
SU.error("mo command contains " .. text .. ", which is not text")
SU.error("mo command contains content which is not text")
end
return b.text("operator", attributes, script, text)
elseif content.command == "mn" then
local script = content.options.mathvariant and b.mathVariantToScriptType(content.options.mathvariant)
or b.scriptType.upright
local text = content[1]
if type(text) ~= "string" then
SU.error("mn command contains " .. text .. ", which is not text")
SU.error("mn command contains content which is not text")
end
if string.sub(text, 1, 1) == "-" then
text = "" .. string.sub(text, 2)
Expand Down Expand Up @@ -136,6 +136,19 @@ function ConvertMathML (_, content)
return b.mtr(convertChildren(content))
elseif content.command == "mtd" then
return b.stackbox("H", convertChildren(content))
elseif content.command == "mtext" or content.command == "ms" then
if #content > 1 then
SU.error("Wrong number of children in " .. content.command .. ": " .. #content)
end
local text = content[1] or "" -- empty mtext is allowed, and found in examples...
if type(text) ~= "string" then
SU.error(content.command .. " command contains content which is not text")
end
-- MathML Core 3.2.1.1 Layout of <mtext> has some wording about forced line breaks
-- and soft wrap opportunities: ignored here.
-- There's also some explanations about CSS, italic correction etc. which we ignore too.
text = text:gsub("[\n\r]", " ")
return b.text("string", {}, b.scriptType.upright, text:gsub("%s+", " "))
else
SU.error("Unknown math command " .. content.command)
end
Expand Down
10 changes: 8 additions & 2 deletions packages/math/unicode-symbols.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2567,10 +2567,12 @@ symbols.alpha = "α"
symbols.beta = "β"
symbols.gamma = "γ"
symbols.delta = "δ"
symbols.epsilon = "ε"
symbols.epsilon = "ϵ"
symbols.varepsilon = "ε"
symbols.zeta = "ζ"
symbols.eta = "η"
symbols.theta = "θ"
symbols.vartheta = "ϑ"
symbols.iota = "ι"
symbols.kappa = "κ"
symbols.lambda = "λ"
Expand All @@ -2579,11 +2581,15 @@ symbols.nu = "ν"
symbols.xi = "ξ"
symbols.omicron = "ο"
symbols.pi = "π"
symbols.varpi = "ϖ"
symbols.rho = "ρ"
symbols.varrho = "ϱ"
symbols.sigma = "σ"
symbols.varsigma = "ς"
symbols.tau = "τ"
symbols.upsilon = "υ"
symbols.phi = "φ"
symbols.phi = "ϕ"
symbols.varphi = "φ"
symbols.chi = "χ"
symbols.psi = "ψ"
symbols.omega = "ω"
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub struct Cli {
/// Set or override document class options.
///
/// Can be used to change default options or override the ones specified in a document.
/// For example setting `--options papersize=letter` would override both the default `papersize` of A4 and any specific one set in the document’s options.
/// For example setting `--option papersize=letter` would override both the default `papersize` of A4 and any specific one set in the document’s options.
/// May be specified more than once.
#[clap(short = 'O', long)]
#[clap(short = 'O', long, alias = "options")]
pub option: Option<Vec<String>>,

/// Include the contents of a SIL, XML, or other resource file before the input document content.
Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ pub fn run(
has_input_filename = true;
}
if let Some(options) = options {
sile_input.set("options", options)?;
// TODO: when mlua v0.10 merges, adapt this like the uses parsing to avoid chunking
for option in options.iter() {
let option = lua.create_string(option)?;
lua.load(chunk! {
local parameter = SILE.parserBits.parameters:match($option);
SILE.input.options = pl.tablex.merge(SILE.input.options, parameter, true)
})
.eval::<()>()?;
}
}
if let Some(modules) = uses {
// let parser_bits: LuaTable = sile.get("parserBits")?;
Expand Down
4 changes: 2 additions & 2 deletions tests/math-bigops.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ Integrals, display (large font), MathML:
Integrals, text, TeX:
<math>
\oiint_S \mi[mathvariant=bold]{E} \cdot
\mi[mathvariant=bold]{dS} = \frac{1}{\epsilon_0}
\mi[mathvariant=bold]{dS} = \frac{1}{\varepsilon_0}
\iiint_V \rho \mi[mathvariant=normal]{dV}
= \int_0^x {f(t)\mo{d}t}
</math>

Integrals, display, TeX:
<math mode="display">
\oiint_S \mi[mathvariant=bold]{E} \cdot
\mi[mathvariant=bold]{dS} = \frac{1}{\epsilon_0}
\mi[mathvariant=bold]{dS} = \frac{1}{\varepsilon_0}
\iiint_V \rho \mi[mathvariant=normal]{dV}
= \int_0^x {f(t)\mo{d}t}
</math>
Expand Down

0 comments on commit bd2dd1a

Please sign in to comment.