Skip to content

Commit

Permalink
feat: command \center now has an option to center its content vertically
Browse files Browse the repository at this point in the history
  • Loading branch information
jodros committed Oct 21, 2023
1 parent 7bd675e commit 0e7ea06
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion classes/plain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,14 @@ function class:registerCommands ()
SILE.settings:set("linebreak.tolerance", 10000)
end)

self:registerCommand("center", function (_, content)
self:registerCommand("center", function (options, content)
if #SILE.typesetter.state.nodes ~= 0 then
SU.warn("\\center environment started after other nodes in a paragraph, may not center as expected")
end
if SU.boolean(options.vertical) then
SILE.call("hbox")
SILE.call("vfill")
end
SILE.settings:temporarily(function()
SILE.settings:set("current.parindent", 0)
SILE.settings:set("document.parindent", 0)
Expand Down
47 changes: 47 additions & 0 deletions tests/centering-vertically.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Set paper size 595.275597 841.8897729
Begin page
Mx 49.7638
My 42.0945
Mx 160.4430
My 288.5648
Set font Gentium Plus;10;400;;normal;;;LTR
T 55 43 44 54 w=19.7852 (THIS)
Mx 182.8707
T 51 43 53 36 54 40 w=33.0518 (PHRASE)
Mx 218.5650
T 54 43 50 56 47 39 w=34.5264 (SHOULD)
Mx 255.7340
T 37 40 w=10.4590 (BE)
Mx 268.8356
Mx 4.9609
Mx 6.1523
Mx 5.8008
Mx 5.3613
Mx 5.5078
Mx 4.0820
Mx 5.9424
T 40 a=4.9609 59 a=6.1523 36 a=5.9521 38 a=5.3613 55 a=5.5078 47 a=4.7607 60 a=5.9424 (EXACTLY)
Mx 309.2857
Mx 5.4639
Mx 5.5078
T 36 a=5.9521 55 a=5.5078 (AT)
Mx 322.9000
T 55 43 40 w=17.0068 (THE)
Mx 342.5494
T 48 44 39 39 47 40 w=32.6172 (MIDDLE)
Mx 377.8092
T 50 41 w=10.7813 (OF)
Mx 391.2330
T 55 43 40 w=17.0068 (THE)
Mx 410.8824
Mx 4.6387
Mx 5.8008
Mx 5.8301
Mx 4.9609
T 51 a=5.2295 36 a=5.9521 42 a=5.8301 40 a=4.9609 (PAGE)
T 4 w=2.7197 (!)
Mx 295.2916
My 780.6177
T 20 w=4.6924 (1)
End page
Finish
3 changes: 3 additions & 0 deletions tests/centering-vertically.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{document}
\center[vertical=true]{THIS PHRASE SHOULD BE EXACTLY AT THE MIDDLE OF THE PAGE!}
\end{document}

0 comments on commit 0e7ea06

Please sign in to comment.