Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command \center now has an option to center its content vertically #1898

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
.sources
key: fonts-${{ hashFiles('Makefile-fonts') }}
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v5
uses: DeterminateSystems/nix-installer-action@v6
- name: Cache Nix dependencies
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Setup developer environment
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
fetch-depth: 0
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v5
uses: DeterminateSystems/nix-installer-action@v6
- name: Cache Nix dependencies
uses: DeterminateSystems/magic-nix-cache-action@v2
# Upstream package sometimes has flags set that disable flake checking
Expand Down
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")
Copy link
Member

@Omikhleia Omikhleia Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A vfill won't push the content middle of the page, unless if it is a final page automatically vfill'ed (such as the final page of your example) or explicitly \eject'ed. Then another vfill is currently automatically added at the end of the page, resulting in centering.

Personally:

  • I don't think that horizontal centering and vertical centering should be the same command
  • I don' think the vfill added on final pages or via eject is actually good :)

EDIT: Oh, and by the way, the empty hbox is no innocuous. It introduces an empty line. With the default typesetter, this is nearly innocuous, as it has a height of 0. With any other linespacing strategy (from the eponymous package, broken, IMHO) or grid, it becomes messy.

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}
Loading