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

feat: option to make folio on left if even and on right if odd #1952

Draft
wants to merge 1 commit 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
28 changes: 24 additions & 4 deletions packages/folio/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ function package:_init (options)
self:export("outputFolio", self.outputFolio)
end

function package:declareSettings(_)
SILE.settings:declare({
parameter = "folio.style",
default = "center",
type = "string"
})
end

function package:registerCommands ()

self:registerCommand("folios", function (_, _)
Expand All @@ -71,7 +79,16 @@ function package:registerCommands ()
end, "Deprecated")

self:registerCommand("foliostyle", function (_, content)
SILE.call("center", {}, content)
local style = SILE.settings:get("folio.style")
if style == "mirror" then
Copy link
Member

Choose a reason for hiding this comment

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

I like the feature and we should definitely support some way to handle this out of the box (since our currently documented "easy" way doesn't actually work). But this approach is just a bit too naive. In a RTL document where the writing direction is reversed, the "mirrored" pages are also the opposite of what most LTR readers expect: in a bound books odd pages are on the left and even pages are on the right.

Copy link
Contributor Author

@jodros jodros Jan 4, 2024

Choose a reason for hiding this comment

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

Would this solve the point?

      local ltr = (SILE.settings:get("font.direction") == "LTR")
      local evenPage = (SILE.scratch.counters.folio.value % 2 == 0)
        
      if (ltf and evenPage) or (not ltr and not evenPage) then
        SILE.call("raggedleft", {}, content)
      else
        SILE.call("raggedright", {}, content) 
      end

Copy link
Member

Choose a reason for hiding this comment

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

Maybe. I haven't looked into when/where this is typically set vs. when/where this would be trying to read it. Also it would be complicated in a mixed-language environment. For example how would this folio function cope with a master frame layout for a parallel English/Arabic text with balanced frames? I'm wondering if a more robust setting might not be just to call out weather the "right" and "left" alignments should be on odd or even pages directly without trying to guess from the direction settings of the typesetter at some random point or some frame when there might be other considerations. Also what if people want to use the mirroring but just have a layout that is flipped from this expectation? Maybe they want their page numbers on the inside instead of the outside.

Thinking out loud here, but I'm leading towards a more explicit setting rather than trying to guess.

Copy link
Member

Choose a reason for hiding this comment

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

It might be confusing too, if the folio frame doesn't span the whole page in some layouts (left/right mirrored alignment applying to the frame content regardless of its actual position) -- But I don't really know either, yet, what would be a proper way to better define it.

Copy link
Member

Choose a reason for hiding this comment

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

In almost all cases that my pea brain on 2 hours of sleep can think off off the cuff, if the folio frame does not span the whole page then almost certainly centered is going to be the wrong expectation. In those cases being aligned to one side or the other seems like it would be expected.

This does bring up an interesting issue we have with odd/even headers as well. Mirroring the frame isn't enough to reflect the design, we also have style functions that vary for different sides (in the case of headers, sometimes also for content of course but that's different).

I'm even more convinced today than I was yesterday that we shouldn't be guessing at all and should just take some explicit option. But is it possible we have some property of the frame itself that could be used for a typesetter to derive the intentions while also allowing the masters package to mirror it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course this wouldn't work for documents with multiple columns, since it's just a draft... But that's one of the tests to be made as well, right?

 if SILE.frames.folio:right() == SILE.frames.content:right() and
    SILE.frames.folio:left() == SILE.frames.content:left() then
    ...

if SILE.scratch.counters.folio.value % 2 == 0 then
SILE.call("raggedright", {}, content)
else
SILE.call("raggedleft", {}, content)
end
else
SILE.call("center", {}, content)
end
end)

end
Expand All @@ -95,9 +112,12 @@ If, for instance, you want to set page numbers in a different font you can redef
\define[command=foliostyle]{\center{\font[family=Albertus]{\process}}}
\end{raw}

If you want to put page numbers on the left side of even pages and the right side of odd pages, there are a couple of ways you can do that.
The complicated way is to define a command in Lua which inspects the page number and then sets the number ragged left or ragged right appropriately.
The easy way is just to put your folio frame where you want it on the master page.
If you want to put page numbers on the left side of even pages and the right side of odd pages you can just set the settings' parameter \code{folio.style} to \code{mirror}:

\begin[type=autodoc:codeblock]{raw}
\set[parameter=folio.style, value=mirror]
\end{raw}

\end{document}
]]

Expand Down
12 changes: 12 additions & 0 deletions tests/foliomirrored.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Set paper size 595.275597 841.8897729
Begin page
Mx 560.8194
My 780.6177
Set font Gentium Plus;10;400;;normal;;;LTR
T 20 w=4.6924 (1)
New page
Mx 29.7638
My 780.5689
T 21 w=4.6924 (2)
End page
Finish
4 changes: 4 additions & 0 deletions tests/foliomirrored.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\begin{document}
\set[parameter=folio.style, value=mirror]
\eject
\end{document}
Loading