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

Prototype for “inline cutting note” #6

Open
RuixiZhang42 opened this issue Jun 23, 2022 · 2 comments
Open

Prototype for “inline cutting note” #6

RuixiZhang42 opened this issue Jun 23, 2022 · 2 comments
Assignees

Comments

@RuixiZhang42
Copy link
Owner

Syntax

  • \cuttingnote{⟨note text⟩}
  • \cuttingnote[⟨number of stacked lines⟩]{⟨note text⟩}
  • \cuttingnote[⟨number of stacked lines⟩][⟨decimal or fraction⟩]{⟨note text⟩}

The ⟨number of stacked lines⟩

The first optional argument, ⟨number of stacked lines⟩, represents the number of lines that should be stacked for arranging the ⟨note text⟩ of this inline cutting note. It can be any arbitrary integer expression accepted by \numexpr...\relax. The default is 2. For example,

  • \cuttingnote[2]{⟨note text⟩}, equivalent to \cuttingnote{⟨note text⟩}
  • \cuttingnote[3]{⟨note text⟩}
  • \cuttingnote[(1+6)/2-3]{⟨note text⟩}, equivalent to \cuttingnote[1]{⟨note text⟩}

The ⟨decimal or fraction⟩

The second optional argument, ⟨decimal or fraction⟩, represents the length (in units of ideographic width) that should be occupied by the ⟨note text⟩ of this inline cutting note. This length does not include the opening and closing brackets (if present) of the inline cutting note. For example,

  • \cuttingnote[2][12]{⟨note text⟩} means that the ⟨note text⟩ should be fit into two stacked lines, each of which measures 12-ideograph long (and thus at most 2×12=24 hanzi characters can be fit in).

    If the ⟨note text⟩ is much longer, then the head 24-hanzi-character amount of the ⟨note text⟩ will be typeset in two stacked lines, followed by a forced line break, and thus wrapping the remaining ⟨note text⟩ onto the next main text line. The remaining ⟨note text⟩ will of course be typeset in the same ⟨number of stacked lines⟩. But if it still cannot be fit into this new main text line, the leftover ⟨note text⟩ will be wrapped onto the next main text line, and so on, until the tail of the original ⟨note text⟩ is fit in and typeset.

The intended use for this second optional argument is to manually break a long ⟨note text⟩. Common and useful input includes integers (11, 12, etc.) and half-integers (11.5, 12.5, etc.), because of the full-width/square nature of ideographs and the half-width nature of many CJK punctuation marks. Fraction expressions such as 205/13 and "CD/'15 are also accepted (by the way, these two fractions both represent approximately 15.76923).

Dealing with erroneous input

Zero or negative ⟨number of stacked lines⟩

If the given ⟨number of stacked lines⟩ evaluates to zero or some negative integer, then this optional argument along with the second optional argument (if present) will be ignored, and the ⟨note text⟩ will be processed by the identity function \@firstofone (\use:n) and thus will be typeset as part of the main text.

For example, the following erroneous input

  • ⟨pre-note main text⟩\cuttingnote[0]{⟨note text⟩}⟨post-note main text⟩ or
  • ⟨pre-note main text⟩\cuttingnote[0][12]{⟨note text⟩}⟨post-note main text⟩ or
  • ⟨pre-note main text⟩\cuttingnote[6-8]{⟨note text⟩}⟨post-note main text⟩ or
  • ⟨pre-note main text⟩\cuttingnote[(9-11)/3][9.5]{⟨note text⟩}⟨post-note main text⟩

will all be treated as ⟨pre-note main text⟩⟨note text⟩⟨post-note main text⟩. This is not the same as ⟨pre-note main text⟩\cuttingnote[1]{⟨note text⟩}⟨post-note main text⟩.

I originally thought about using \@gobble (\use_none:n) instead of \@firstofone (\use:n), so that the ⟨note text⟩ would simply disappear for such nonsensical ⟨number of stacked lines⟩. However, the users will likely be baffled by the disappearance of their ⟨note text⟩. Moreover, this is not a good solution when dealing with nested inline cutting notes (see below).

Nested inline cutting notes

It makes no sense to nest inline cutting notes. Therefore, as soon as we enter into a valid inline cutting note—one with a positive ⟨number of stacked lines⟩—any inner \cuttingnote’s will essentially behave like the identity function.

For example (assuming the first \cuttingnote is not already inside another \cuttingnote of course), the following erroneous input

  • \cuttingnote{...\cuttingnote{⟨inner-note text⟩}...} or
  • \cuttingnote{...\cuttingnote[0]{⟨inner-note text⟩}...} or
  • \cuttingnote{...\cuttingnote[3][16]{⟨inner-note text⟩}...}

will all be treated as \cuttingnote{...⟨inner-note text⟩...}. Likewise, the following erroneous input

  • \cuttingnote[1]{...\cuttingnote[2]{,,,\cuttingnote[3]{⟨inner-inner-note text⟩},,,}...}

will be treated as \cuttingnote[1]{...,,,⟨inner-inner-note text⟩,,,...}.

Exercise. What about the following input?

  • ⟨pre-note main text⟩\cuttingnote[0]{...\cuttingnote[0]{,,,\cuttingnote[3]{⟨inner-inner-note text⟩},,,}...\cuttingnote[3]{;;;\cuttingnote[3]{⟨another inner-inner-note text⟩};;;}...}⟨post-note main text⟩

Answer. It will be treated as ⟨pre-note main text⟩...,,,\cuttingnote[3]{⟨inner-inner-note text⟩},,,...\cuttingnote[3]{;;;⟨another inner-inner-note text⟩;;;}...⟨post-note main text⟩. The first \cuttingnote[3] survives despite being nested two levels deep, since the outer two \cuttingnote[0]’s are invalid. Similarly, the second \cuttingnote[3] survives despite being nested one level deep. The third \cuttingnote[3] is reduced to the identity function, since it is inside a valid \cuttingnote[3].

@RuixiZhang42 RuixiZhang42 self-assigned this Jun 23, 2022
@RuixiZhang42
Copy link
Owner Author

Prerequisites

In this comment, I will try to list off all dependencies of my implementation.

The LaTeX format

My implementation requires access to eTeX’s expressions (\numexpr, \dimexpr, \glueexpr), LaTeX’s commands (e.g., \@firstofone/\use:n), and LaTeX’s NFSS (e.g., \f@size). My implementation works on both XeLaTeX and LuaLaTeX (I think), though newxeCJK runs on XeLaTeX only.

A version that runs on plain eTeX can be derived from my implementation. Too much work, though.

\AssignScaledResult

My implementation requires \AssignScaledResult to work with ⟨decimal or fraction⟩. I also assume hacking into NFSS with \AssignScaledResult.

See https://github.com/RuixiZhang42/font-pairing-guide/blob/master/allow-frac-scale.tex for its implementation.

\CJKscale

I have defined \CJKscale as a fraction

\newcommand*\CJKscale{93951/101600}% 13Q/10pt

and have used it in

\input{allow-frac-scale}% hacking into NFSS already!
\setCJKmainfont{...}[
  ...,
  Scale=\CJKscale
]

This way, at any requested font size (\f@sizept), the size of an ideograph equals exactly \dimexpr\f@size\p@*\CJKscale\relax.

The condensed ratio of ideographs, \l__newxeCJK_CJK_condensed_ratio_tl, is not handled (yet). Right now, all ideographs are assumed to be in a square.

\l__newxeCJK_CJK_mid_ht_ratio_tl

This internal variable is not introduced into newxeCJK (yet). It should be a fraction of the ideograph size, measuring the distance between the center of an ideograph and the (Latin) baseline. For example,

%<@@=newxeCJK>
% Horizontal text with the Source Han family of fonts
\tl_set:Nn \l_@@_CJK_mid_ht_ratio_tl { 380 / 1000 }
% Vertical text with any CJK fonts
\tl_set:Nn \l_@@_CJK_mid_ht_ratio_tl { 0 }

This is needed for aligning the inline cutting note with respect to the main text. In horizontal text, the possibilities are top/center/bottom alignments. In vertical text, the possibilities are right/center/left alignments.

@RuixiZhang42
Copy link
Owner Author

Gallery

The layout design is based on article’s default 10pt body on 12pt leading. The resolution is approximately 148 DPI.

Vertical text

Text: 後漢書, by 范曄, annotated by 李賢 et al.

Layout: 13Q body on 30‌1⁄3‌H leading (main text) and 9Q body on 9H leading (inline cutting note). The title is in 18Q and occupies two main text lines, aligned to the right edge.

cuttingnotev

Horizontal text

Text: The TeXbook, by Donald E. Knuth.

Layout: 13Q body on 30H leading (main text) and 9Q body on 10H leading (inline cutting note, with English text in 6.88pt).

cuttingnoteh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant