Skip to content

Commit

Permalink
refactor: remove the use of mark for sectioning
Browse files Browse the repository at this point in the history
use variable directly
  • Loading branch information
LogCreative committed Jun 29, 2023
1 parent c081c85 commit b2b4cf3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 50 deletions.
93 changes: 43 additions & 50 deletions source/pretfg.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -120,34 +120,35 @@
%
% \begin{implementation}
%
% NOTE: For the implementation of foreground/sectioning, use variable of \LaTeX3
% directly instead of the traditional mark, since the traditional mark
% only gets updated when the page is created. Sometimes a higher level of
% sectioning gets inserted and no intermediate information until the next
% sectioning level, and the information could be swallowed since it only
% compares the information from the previous page state, which is not
% beneficial for the new \presenter{} mechanism running.
%
% \pkg{default} style.
% foreground/headline is implemented using the basic \tn{rightmark}.
% foreground/sectioning just uses \tn{markright} for basic general availablity.
% \begin{macrocode}
%<*default>
%<@@=pretfg_default>
\tl_new:N \l_@@_fg_headline_title_tl
\tl_new:N \l_@@_fg_headline_style_tl
\DeclareTemplateCode { foreground / headline } { default } { 0 }
{ style = \l_@@_fg_headline_style_tl }
{
\AssignTemplateKeys
\group_begin:
\l_@@_fg_headline_style_tl
\rightmark
\tl_use:N \l_@@_fg_headline_title_tl
\group_end:
\hfil
}
% \end{macrocode}
% \pkg{default} style of foreground/sectioning just uses \tn{markright}.
% \begin{macrocode}
\DeclareTemplateCode { foreground / sectioning } { default } { 2 }
{ }
{
\markright { #2 }
\tl_set:Nn \l_@@_fg_headline_title_tl { #2 }
}
% \end{macrocode}
% foreground/footline will print the page number.
% \begin{macrocode}
\tl_new:N \l_@@_fg_footline_style_tl
\DeclareTemplateCode { foreground / footline } { default } { 0 }
{ style = \l_@@_fg_footline_style_tl }
Expand Down Expand Up @@ -178,8 +179,6 @@
% \l_@@_fg_headline_cur_sec_lv_int
% }
% Store the previous or the current section level.
% Here an int variable is used instead of a mark, since the mark grabbed by
% \cs{LastMark} is not expandable and cannot be processed by \cs{int_eval:n}.
% \begin{macrocode}
\int_new:N \l_@@_fg_headline_prev_sec_lv_int
\int_set_eq:NN \l_@@_fg_headline_prev_sec_lv_int
Expand All @@ -202,23 +201,10 @@
\box_new:N \l_@@_fg_headline_parent_box
% \end{macrocode}
% \end{variable}
%
% Here, \presenter{} uses the new mark mechanism instead of legacy \tn{leftmark}
% and \tn{rightmark} for the following reasons:
% \begin{itemize}
% \item \LaTeX3 now encourages to use the new interface and the source code of
% the \LaTeX{} format \file{ltmarks.dtx} has already swapped the original
% implementation of those commands to the new version.
% \item The current implementation needs to take care of three marks instead of
% only two marks.
% \item Maybe the star mark is not necessary, since the design could be changed
% in the future. But using the new interface will make the comparsion of
% marks easier.
% \end{itemize}
% \begin{macrocode}
\NewMarkClass { pretprevmark }
\NewMarkClass { pretcurmark }
\NewMarkClass { pretstarmark }
\tl_new:N \l_@@_fg_headline_prev_title_tl
\tl_new:N \l_@@_fg_headline_cur_title_tl
\tl_new:N \l_@@_fg_headline_star_title_tl
% \end{macrocode}
% It seems to be in horizontal mode in the header, use a \cs{vbox} to create a
% vertical mode environment in order to adjust the vertical position of the
Expand All @@ -242,26 +228,32 @@
\group_begin:
\bool_if:NTF \l_@@_fg_headline_star_mark_bool
{
\l_@@_fg_headline_child_style_tl
\LastMark { pretstarmark }
\l_@@_fg_headline_child_style_tl
\tl_use:N \l_@@_fg_headline_star_title_tl
}
{
\mark_if_eq:nnnnnnTF { page } { pretprevmark } { last }
{ page } { pretcurmark } { last }
{
\l_@@_fg_headline_child_style_tl
\LastMark { pretcurmark }
}
{
\vbox_set:Nn \l_@@_fg_headline_parent_box
{ \l_@@_fg_headline_parent_style_tl \LastMark { pretprevmark } }
\vbox:n {
\skip_vertical:n { - \box_ht_plus_dp:N \l_@@_fg_headline_parent_box }
\l_@@_fg_headline_parent_style_tl \LastMark { pretprevmark }
\skip_vertical:N \c_zero_dim
\l_@@_fg_headline_child_style_tl \LastMark { pretcurmark }
\tl_if_eq:NNTF \l_@@_fg_headline_prev_title_tl
\l_@@_fg_headline_cur_title_tl
{
\l_@@_fg_headline_child_style_tl
\tl_use:N \l_@@_fg_headline_cur_title_tl
}
{
\vbox_set:Nn \l_@@_fg_headline_parent_box
{
\l_@@_fg_headline_parent_style_tl
\tl_use:N \l_@@_fg_headline_prev_title_tl
}
\vbox:n {
\skip_vertical:n
{ - \box_ht_plus_dp:N \l_@@_fg_headline_parent_box }
\l_@@_fg_headline_parent_style_tl
\tl_use:N \l_@@_fg_headline_prev_title_tl
\skip_vertical:N \c_zero_dim
\l_@@_fg_headline_child_style_tl
\tl_use:N \l_@@_fg_headline_cur_title_tl
}
}
}
}
\group_end:
\hfil
Expand All @@ -272,7 +264,7 @@
\tl_if_eq:nnTF { #1 } { star }
{
\bool_set_true:N \l_@@_fg_headline_star_mark_bool
\InsertMark { pretstarmark } { #2 }
\tl_set:Nn \l_@@_fg_headline_star_title_tl { #2 }
}
{
\bool_set_false:N \l_@@_fg_headline_star_mark_bool
Expand All @@ -287,12 +279,13 @@
{ \l_@@_fg_headline_cur_sec_lv_int } >
{ \l_@@_fg_headline_prev_sec_lv_int }
{
\InsertMark { pretprevmark } { \LastMark { pretcurmark } }
\InsertMark { pretcurmark } { #2 }
\tl_set_eq:NN \l_@@_fg_headline_prev_title_tl
\l_@@_fg_headline_cur_title_tl
\tl_set:Nn \l_@@_fg_headline_cur_title_tl { #2 }
}
{
\InsertMark { pretprevmark } { #2 }
\InsertMark { pretcurmark } { #2 }
\tl_set:Nn \l_@@_fg_headline_prev_title_tl { #2 }
\tl_set:Nn \l_@@_fg_headline_cur_title_tl { #2 }
}
\int_set_eq:NN \l_@@_fg_headline_prev_sec_lv_int
\l_@@_fg_headline_cur_sec_lv_int
Expand Down
1 change: 1 addition & 0 deletions testfiles/dual.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Testing the text in the subsubsection.

Testing the text in the paragraph.

\section{New section}
\subparagraph{A small point}

Testing the text in the subparagraph.
Expand Down

0 comments on commit b2b4cf3

Please sign in to comment.