texrs 0.6.8

A TeX engine: Knuth's mouth and expander, lowered for a bytecode VM
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
//! Displaying a list: `tex.web` §173-§198.
//!
//! `\showbox`, `\showlists` and every `Overfull \hbox` message describe a list
//! in the same symbolic form, and a reader compares it against tex's log
//! character for character -- so this is the port of `show_node_list` and
//! `short_display`, with tex's spacing, its omissions and its truncation
//! rules, not a pretty-printer that happens to look similar.
//!
//! Two of tex's rules decide most of what a display looks like:
//!
//! - The nesting history is a STRING, one `.` per level (§180's
//!   `node_list_display` appends one, recurses, and flushes it), and each
//!   line starts with it. A discretionary's post-break list is introduced with
//!   `|` instead (§195), so `.|` is "inside the post-break text".
//! - `\showboxdepth` and `\showboxbreadth` (§181, §236) cut the display off:
//!   a list deeper than the depth prints ` []`, and the item past the breadth
//!   prints `etc.`. A non-positive breadth means 5 (§198).
//!
//! A glue's spec is printed with NO unit (§189's `print_spec(glue_ptr(p),0)`),
//! which is why a box display reads `\glue 3.33333 plus 1.66666` where `\the`
//! would write `3.33333pt plus 1.66666pt`.

use super::{BoxNode, GlueSign, GlueSource, LeaderKind, Node, Scaled};
use crate::dimen::{print_scaled, UNITY};
use crate::math::noad::{Class, Delimiter, Field, Limits, MathChar, Noad, Style};

/// The names a display needs from the font table: §267's `font_id_text`,
/// which is the control sequence `\font` defined (`tenrm`), not the file name.
pub trait FontIds {
    /// The identifier of internal font `f`, without its escape character.
    fn font_id_text(&self, f: usize) -> String;
}

/// A font table that names every font by its number, for a caller with no
/// table of its own.
pub struct Numbered;

impl FontIds for Numbered {
    fn font_id_text(&self, f: usize) -> String {
        format!("FONT{f}")
    }
}

/// What a display prints with: §236's `\showboxdepth` and `\showboxbreadth`,
/// and the escape character §63's `print_esc` puts in front of every name.
pub struct Display<'a> {
    /// `depth_threshold` (§181).
    pub depth: i64,
    /// `breadth_max` (§181).
    pub breadth: i64,
    /// The `\escapechar` character, or empty when it is out of range.
    pub esc: &'a str,
    pub fonts: &'a dyn FontIds,
}

/// §68's `print_ASCII` of a character code, under the convention
/// `crate::ir::printed` uses for the rest of texrs's output: a control code
/// in §49's `^^` form, everything else as itself.
fn print_ascii(out: &mut String, c: char) {
    let code = u32::from(c);
    if code < 32 {
        out.push_str("^^");
        out.push(char::from(code as u8 + 64));
    } else if code == 127 {
        out.push_str("^^?");
    } else {
        out.push(c);
    }
}

/// §177's `print_glue`: one component, with its order's name, or `s` when it
/// is finite.
fn print_glue(out: &mut String, d: Scaled, order: crate::glue::Order, s: &str) {
    out.push_str(&print_scaled(d));
    match order {
        o if !(0..=3).contains(&o) => out.push_str("foul"),
        0 => out.push_str(s),
        o => {
            out.push_str("fil");
            for _ in 1..o {
                out.push('l');
            }
        }
    }
}

/// §178's `print_spec`.
pub fn print_spec(out: &mut String, g: &crate::glue::Glue, s: &str) {
    out.push_str(&print_scaled(g.natural));
    out.push_str(s);
    if g.stretch != 0 {
        out.push_str(" plus ");
        print_glue(out, g.stretch, g.stretch_order, s);
    }
    if g.shrink != 0 {
        out.push_str(" minus ");
        print_glue(out, g.shrink, g.shrink_order, s);
    }
}

/// §176's `print_rule_dimen`: a running dimension is `*`.
fn print_rule_dimen(out: &mut String, d: Scaled) {
    match d == super::NULL_FLAG {
        true => out.push('*'),
        false => out.push_str(&print_scaled(d)),
    }
}

/// §225's `print_skip_param`.
fn skip_param_name(code: usize) -> &'static str {
    crate::params::GLUE_NAMES
        .get(code)
        .copied()
        .unwrap_or("[unknown glue parameter!]")
}

impl Display<'_> {
    fn esc(&self, out: &mut String, name: &str) {
        out.push_str(self.esc);
        out.push_str(name);
    }

    /// §176's `print_font_and_char`.
    fn font_and_char(&self, out: &mut String, font: usize, c: char) {
        self.esc(out, &self.fonts.font_id_text(font));
        out.push(' ');
        print_ascii(out, c);
    }

    /// §198's `show_box`: the display of `list` that `\showbox` writes,
    /// starting on a fresh line as §182's first `print_ln` does, and ending
    /// with the `print_ln` §198 adds.
    pub fn show_box(&self, list: &[Node]) -> String {
        let breadth = match self.breadth <= 0 {
            true => 5,
            false => self.breadth,
        };
        let mut out = String::new();
        let mut history = String::new();
        self.show_node_list(&mut out, list, &mut history, breadth);
        out.push('\n');
        out
    }

    /// §182's `show_node_list`.
    fn show_node_list(&self, out: &mut String, list: &[Node], history: &mut String, breadth: i64) {
        if history.len() as i64 > self.depth {
            if !list.is_empty() {
                out.push_str(" []");
            }
            return;
        }
        let mut n = 0i64;
        let mut i = 0usize;
        while i < list.len() {
            out.push('\n');
            out.push_str(history);
            n += 1;
            if n > breadth {
                out.push_str("etc.");
                return;
            }
            self.display_node(out, &list[i], history, breadth);
            i += 1;
        }
    }

    /// §180's `node_list_display`: one level deeper, marked by `.`.
    fn nested(&self, out: &mut String, list: &[Node], history: &mut String, breadth: i64) {
        history.push('.');
        self.show_node_list(out, list, history, breadth);
        history.pop();
    }

    /// §183: display node `p`.
    fn display_node(&self, out: &mut String, p: &Node, history: &mut String, breadth: i64) {
        match p {
            Node::Char(c) => self.font_and_char(out, c.font, c.character),
            Node::Box(b) => {
                self.display_box(out, b);
                self.nested(out, &b.list, history, breadth);
            }
            // §187.
            Node::Rule(r) => {
                self.esc(out, "rule(");
                print_rule_dimen(out, r.height);
                out.push('+');
                print_rule_dimen(out, r.depth);
                out.push_str(")x");
                print_rule_dimen(out, r.width);
            }
            // §188.
            Node::Ins(ins) => {
                self.esc(out, "insert");
                out.push_str(&ins.number.to_string());
                out.push_str(", natural size ");
                out.push_str(&print_scaled(ins.height));
                out.push_str("; split(");
                print_spec(out, &ins.split_top_skip, "");
                out.push(',');
                out.push_str(&print_scaled(ins.depth));
                out.push_str("); float cost ");
                out.push_str(&ins.float_cost.to_string());
                self.nested(out, &ins.list, history, breadth);
            }
            // §1356's `\special` display.
            Node::Whatsit(text) => {
                self.esc(out, "special");
                out.push('{');
                out.push_str(text);
                out.push('}');
            }
            // §1356 for `open_node`, `write_node` and `close_node`: the
            // primitive and its stream (`print_write_whatsit`), then the file
            // name or the unexpanded text, as the lowerer wrote them.
            Node::Out(w) => self.esc(out, &w.display),
            Node::Glue(g) if g.kind.is_leaders() => {
                // §190.
                self.esc(out, "");
                match g.kind {
                    LeaderKind::Centred => out.push('c'),
                    LeaderKind::Expanded => out.push('x'),
                    _ => {}
                }
                out.push_str("leaders ");
                print_spec(out, &g.spec, "");
                if let Some(leader) = &g.leader {
                    self.nested(out, std::slice::from_ref(leader), history, breadth);
                }
            }
            // §189.
            Node::Glue(g) => {
                self.esc(out, "glue");
                if g.source != GlueSource::Normal {
                    out.push('(');
                    match g.source {
                        GlueSource::CondMath => self.esc(out, "nonscript"),
                        GlueSource::MuGlue => self.esc(out, "mskip"),
                        other => self.esc(out, skip_param_name(other.param_code().unwrap_or(99))),
                    }
                    out.push(')');
                }
                if g.source != GlueSource::CondMath {
                    out.push(' ');
                    match g.source {
                        GlueSource::MuGlue => print_spec(out, &g.spec, "mu"),
                        _ => print_spec(out, &g.spec, ""),
                    }
                }
            }
            // §191: an explicit kern is shown by the space after `\kern`.
            Node::Kern { width, explicit } => {
                self.esc(out, "kern");
                if *explicit {
                    out.push(' ');
                }
                out.push_str(&print_scaled(*width));
            }
            Node::AccKern(width) => {
                self.esc(out, "kern");
                out.push(' ');
                out.push_str(&print_scaled(*width));
                out.push_str(" (for accent)");
            }
            // §192.
            Node::Math(width) | Node::MathOff(width) => {
                let side = match p {
                    Node::Math(_) => "mathon",
                    _ => "mathoff",
                };
                self.esc(out, side);
                if *width != 0 {
                    out.push_str(", surrounded ");
                    out.push_str(&print_scaled(*width));
                }
            }
            // §193.
            Node::Ligature(c, lig) => {
                self.font_and_char(out, c.font, c.character);
                out.push_str(" (ligature ");
                if lig.left_boundary {
                    out.push('|');
                }
                for &k in &lig.components {
                    print_ascii(out, k);
                }
                if lig.right_boundary {
                    out.push('|');
                }
                out.push(')');
            }
            // §194.
            Node::Penalty(v) => {
                self.esc(out, "penalty ");
                out.push_str(&v.to_string());
            }
            // §195.
            Node::Disc(d) => {
                self.esc(out, "discretionary");
                if d.replace_count > 0 {
                    out.push_str(" replacing ");
                    out.push_str(&d.replace_count.to_string());
                }
                self.nested(out, &d.pre_break, history, breadth);
                history.push('|');
                self.show_node_list(out, &d.post_break, history, breadth);
                history.pop();
            }
            // §196.
            Node::Mark(text) => {
                self.esc(out, "mark");
                out.push('{');
                out.push_str(text);
                out.push('}');
            }
            // §197.
            Node::Adjust(list) => {
                self.esc(out, "vadjust");
                self.nested(out, list, history, breadth);
            }
        }
    }

    /// §184 and §186: a box's head line.
    fn display_box(&self, out: &mut String, b: &BoxNode) {
        self.esc(out, if b.vertical { "v" } else { "h" });
        out.push_str("box(");
        out.push_str(&print_scaled(b.height));
        out.push('+');
        out.push_str(&print_scaled(b.depth));
        out.push_str(")x");
        out.push_str(&print_scaled(b.width));
        // §186. The `?.?` arm guards against a clobbered word in tex's
        // memory, which a Rust float cannot be.
        let g = b.glue_set;
        if g != 0.0 && b.glue_sign != GlueSign::Normal {
            out.push_str(", glue set ");
            if b.glue_sign == GlueSign::Shrinking {
                out.push_str("- ");
            }
            if g.abs() > 20000.0 {
                match g > 0.0 {
                    true => out.push('>'),
                    false => out.push_str("< -"),
                }
                print_glue(out, 20000 * UNITY, b.glue_order, "");
            } else {
                print_glue(out, (UNITY as f64 * g).round() as Scaled, b.glue_order, "");
            }
        }
        if b.shift_amount != 0 {
            out.push_str(", shifted ");
            out.push_str(&print_scaled(b.shift_amount));
        }
    }

    /// §174's `short_display`: the one-line summary an `Overfull \hbox`
    /// message gives of the list. `font` is `font_in_short_display`, which the
    /// caller starts at `null_font` (§663) and this updates.
    pub fn short_display(&self, out: &mut String, list: &[Node], font: &mut Option<usize>) {
        let mut i = 0usize;
        while i < list.len() {
            match &list[i] {
                Node::Char(c) => {
                    if *font != Some(c.font) {
                        self.esc(out, &self.fonts.font_id_text(c.font));
                        out.push(' ');
                        *font = Some(c.font);
                    }
                    print_ascii(out, c.character);
                }
                // §175.
                Node::Box(_)
                | Node::Ins(_)
                | Node::Whatsit(_)
                | Node::Out(_)
                | Node::Mark(_)
                | Node::Adjust(_) => out.push_str("[]"),
                Node::Rule(_) => out.push('|'),
                Node::Glue(g) if g.spec != crate::glue::Glue::default() => out.push(' '),
                Node::Math(_) | Node::MathOff(_) => out.push('$'),
                // §175: a ligature is shown as what it was made of.
                Node::Ligature(c, lig) => {
                    if *font != Some(c.font) {
                        self.esc(out, &self.fonts.font_id_text(c.font));
                        out.push(' ');
                        *font = Some(c.font);
                    }
                    for &k in &lig.components {
                        print_ascii(out, k);
                    }
                }
                Node::Disc(d) => {
                    self.short_display(out, &d.pre_break, font);
                    self.short_display(out, &d.post_break, font);
                    i += d.replace_count;
                }
                _ => {}
            }
            i += 1;
        }
    }
}

/// The display of mlists, `tex.web` §690-§697: what `\showlists` writes for a
/// formula being built.
impl Display<'_> {
    /// §182's `show_node_list` over an mlist, with the recursion history
    /// starting where `history` stands.
    pub fn show_mlist_from(&self, out: &mut String, list: &[Noad], history: &mut String) {
        let breadth = match self.breadth <= 0 {
            true => 5,
            false => self.breadth,
        };
        self.show_noad_list(out, list, history, breadth);
    }

    fn show_noad_list(&self, out: &mut String, list: &[Noad], history: &mut String, breadth: i64) {
        if history.len() as i64 > self.depth {
            if !list.is_empty() {
                out.push_str(" []");
            }
            return;
        }
        for (n, q) in list.iter().enumerate() {
            out.push('\n');
            out.push_str(history);
            if n as i64 >= breadth {
                out.push_str("etc.");
                return;
            }
            self.display_noad(out, q, history, breadth);
        }
    }

    /// §691's `print_fam_and_char`.
    fn fam_and_char(&self, out: &mut String, c: &MathChar) {
        self.esc(out, "fam");
        out.push_str(&c.fam.to_string());
        out.push(' ');
        print_ascii(out, char::from(c.character));
    }

    /// §691's `print_delimiter`: the 24-bit code in hex.
    fn delimiter(&self, out: &mut String, d: &Delimiter) {
        let a = ((d.small_fam * 256 + usize::from(d.small_char)) * 0x1000)
            + d.large_fam * 256
            + usize::from(d.large_char);
        out.push_str(&format!("\"{a:X}"));
    }

    /// §692's `print_subsidiary_data`.
    fn subsidiary(&self, out: &mut String, f: &Field, c: char, history: &mut String, breadth: i64) {
        if history.len() as i64 >= self.depth {
            if !f.is_empty() {
                out.push_str(" []");
            }
            return;
        }
        history.push(c);
        match f {
            Field::Char(m) => {
                out.push('\n');
                out.push_str(history);
                self.fam_and_char(out, m);
            }
            Field::Box(b) => {
                self.show_node_list(
                    out,
                    std::slice::from_ref(&Node::Box(b.as_ref().clone())),
                    history,
                    breadth,
                );
            }
            Field::List(l) if l.is_empty() => {
                out.push('\n');
                out.push_str(history);
                out.push_str("{}");
            }
            Field::List(l) => self.show_noad_list(out, l, history, breadth),
            Field::Literal(ch) => {
                out.push('\n');
                out.push_str(history);
                print_ascii(out, *ch);
            }
            Field::Empty => {}
        }
        history.pop();
    }

    /// §694's `print_style`.
    fn style(&self, out: &mut String, s: Style) {
        match s / 2 {
            0 => self.esc(out, "displaystyle"),
            1 => self.esc(out, "textstyle"),
            2 => self.esc(out, "scriptstyle"),
            3 => self.esc(out, "scriptscriptstyle"),
            _ => out.push_str("Unknown style!"),
        }
    }

    /// §690, §695-§697.
    fn display_noad(&self, out: &mut String, q: &Noad, history: &mut String, breadth: i64) {
        let atom = match q {
            Noad::Style(s) => return self.style(out, *s),
            Noad::Choice(c) => {
                self.esc(out, "mathchoice");
                for (ch, l) in [
                    ('D', &c.display),
                    ('T', &c.text),
                    ('S', &c.script),
                    ('s', &c.script_script),
                ] {
                    history.push(ch);
                    self.show_noad_list(out, l, history, breadth);
                    history.pop();
                }
                return;
            }
            Noad::Fraction(f) => {
                self.esc(out, "fraction, thickness ");
                match f.thickness {
                    None => out.push_str("= default"),
                    Some(t) => out.push_str(&print_scaled(t)),
                }
                if !f.left_delimiter.is_null() {
                    out.push_str(", left-delimiter ");
                    self.delimiter(out, &f.left_delimiter);
                }
                if !f.right_delimiter.is_null() {
                    out.push_str(", right-delimiter ");
                    self.delimiter(out, &f.right_delimiter);
                }
                self.subsidiary(
                    out,
                    &Field::List(f.numerator.clone()),
                    '\\',
                    history,
                    breadth,
                );
                self.subsidiary(
                    out,
                    &Field::List(f.denominator.clone()),
                    '/',
                    history,
                    breadth,
                );
                return;
            }
            Noad::Left(d) | Noad::Right(d) => {
                let name = match q {
                    Noad::Left(_) => "left",
                    _ => "right",
                };
                self.esc(out, name);
                self.delimiter(out, d);
                return;
            }
            Noad::Node(n) => return self.display_node(out, n, history, breadth),
            Noad::Glue(w) | Noad::Kern(w) => {
                self.esc(out, "kern");
                out.push_str(&print_scaled(*w));
                return;
            }
            Noad::MuKern(w) => {
                self.esc(out, "mkern");
                out.push_str(&print_scaled(*w));
                out.push_str("mu");
                return;
            }
            Noad::MuGlue(g) => {
                self.esc(out, "glue(");
                self.esc(out, "mskip");
                out.push_str(") ");
                out.push_str(&print_scaled(g.natural));
                out.push_str("mu");
                return;
            }
            Noad::Atom(a) => {
                let name = match a.class() {
                    Class::Ord => "mathord",
                    Class::Op => "mathop",
                    Class::Bin => "mathbin",
                    Class::Rel => "mathrel",
                    Class::Open => "mathopen",
                    Class::Close => "mathclose",
                    Class::Punct => "mathpunct",
                    Class::Inner => "mathinner",
                };
                self.esc(out, name);
                a
            }
            Noad::Over(a) => {
                self.esc(out, "overline");
                a
            }
            Noad::Under(a) => {
                self.esc(out, "underline");
                a
            }
            Noad::VCenter(a) => {
                self.esc(out, "vcenter");
                a
            }
            Noad::Radical(r) => {
                self.esc(out, "radical");
                self.delimiter(out, &r.left_delimiter);
                &r.nucleus
            }
            Noad::Accent(acc) => {
                self.esc(out, "accent");
                self.fam_and_char(out, &acc.accent);
                &acc.atom
            }
        };
        match atom.limits {
            Limits::Normal => {}
            Limits::Above => self.esc(out, "limits"),
            Limits::Beside => self.esc(out, "nolimits"),
        }
        self.subsidiary(out, &atom.nucleus, '.', history, breadth);
        self.subsidiary(out, &atom.supscr, '^', history, breadth);
        self.subsidiary(out, &atom.subscr, '_', history, breadth);
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::glue::Glue;
    use crate::node::{CharNode, GlueNode, RuleNode};

    struct Tenrm;
    impl FontIds for Tenrm {
        fn font_id_text(&self, _f: usize) -> String {
            "tenrm".to_string()
        }
    }

    fn display() -> Display<'static> {
        Display {
            depth: 2147483647,
            breadth: 2147483647,
            esc: "\\",
            fonts: &Tenrm,
        }
    }

    fn ch(c: char, width: Scaled) -> Node {
        Node::Char(CharNode {
            font: 1,
            character: c,
            width,
            height: 0,
            depth: 0,
        })
    }

    /// tex's own log for `\setbox0\hbox{abc}\showbox0` under plain.tex,
    /// measured: the kern between b and c is cmr10's, and implicit, so it has
    /// no space after `\kern`.
    #[test]
    fn an_hbox_of_three_letters_reads_as_tex_logs_it() {
        let b = BoxNode {
            width: 1001247,
            height: 455111,
            list: vec![
                ch('a', 327681),
                ch('b', 364090),
                Node::Kern {
                    width: 18205,
                    explicit: false,
                },
                ch('c', 291268),
            ],
            ..BoxNode::null()
        };
        assert_eq!(
            display().show_box(&[Node::Box(b)]),
            "\n\\hbox(6.94444+0.0)x15.27782\n.\\tenrm a\n.\\tenrm b\n.\\kern0.27779\n.\\tenrm c\n"
        );
    }

    /// §189 prints a glue's spec without a unit and names the parameter it
    /// came from; §191 marks an explicit kern by a space; §187 prints a
    /// running dimension as `*`.
    #[test]
    fn glue_kerns_and_rules_follow_sections_187_to_191() {
        let list = vec![
            Node::Glue(GlueNode::param(
                Glue {
                    natural: 12 * UNITY,
                    stretch: UNITY,
                    stretch_order: 1,
                    ..Glue::default()
                },
                GlueSource::BaselineSkip,
            )),
            Node::Kern {
                width: 2 * UNITY,
                explicit: true,
            },
            Node::Rule(RuleNode {
                width: super::super::NULL_FLAG,
                height: 26214,
                depth: 0,
            }),
            Node::Penalty(-10000),
        ];
        assert_eq!(
            display().show_box(&list),
            "\n\\glue(\\baselineskip) 12.0 plus 1.0fil\n\\kern 2.0\n\\rule(0.4+0.0)x*\n\\penalty -10000\n"
        );
    }

    /// §182's two cut-offs: past `\showboxbreadth` items the display says
    /// `etc.`, and below `\showboxdepth` levels a non-empty list is ` []`.
    #[test]
    fn breadth_and_depth_cut_the_display_off() {
        let inner = BoxNode {
            list: vec![ch('x', 0)],
            ..BoxNode::null()
        };
        let d = Display {
            depth: 0,
            breadth: 1,
            ..display()
        };
        assert_eq!(
            d.show_box(&[Node::Box(inner.clone()), ch('y', 0)]),
            "\n\\hbox(0.0+0.0)x0.0 []\netc.\n"
        );
    }

    /// §186: a stretched box says how far, in the order it stretched by.
    #[test]
    fn glue_set_is_printed_with_its_order() {
        let b = BoxNode {
            glue_set: 0.5,
            glue_sign: GlueSign::Stretching,
            glue_order: 1,
            ..BoxNode::null()
        };
        assert_eq!(
            display().show_box(&[Node::Box(b)]),
            "\n\\hbox(0.0+0.0)x0.0, glue set 0.5fil\n"
        );
    }

    /// §193: a ligature is its glyph and, in parentheses, what it was made
    /// of -- cmr10's `fi` is character 12, so `^^L`.
    #[test]
    fn a_ligature_shows_its_components() {
        let fi = Node::Ligature(
            CharNode {
                font: 1,
                character: '\u{c}',
                width: 0,
                height: 0,
                depth: 0,
            },
            crate::node::Ligature {
                components: vec!['f', 'i'],
                ..Default::default()
            },
        );
        assert_eq!(display().show_box(&[fi]), "\n\\tenrm ^^L (ligature fi)\n");
    }

    /// §174: the font is named once, where it changes, and glue is a space.
    #[test]
    fn short_display_names_the_font_once() {
        let mut out = String::new();
        let mut font = None;
        display().short_display(
            &mut out,
            &[
                ch('a', 0),
                Node::Glue(GlueNode::new(Glue::fixed(UNITY))),
                ch('b', 0),
                Node::Rule(RuleNode::running()),
            ],
            &mut font,
        );
        assert_eq!(out, "\\tenrm a b|");
    }
}