Skip to content

Commit 7bf9b30

Browse files
fix: new page between ToC and pre-chapter content (#715)
1 parent 6327265 commit 7bf9b30

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

src/tests/integration/code-content-doc/expected/tex/main.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
\tableofcontents
122122

123123

124+
\cleardoublepage
124125
Here is some code with vertical bars:
125126
\begin{LeanVerbatim}
126127
\textbf{def} or := (· \symbol{124}\symbol{124} ·)

src/tests/integration/front-matter-doc/expected/tex/main.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
\tableofcontents
122122

123123

124+
\cleardoublepage
124125
This is the introduction text that appears before any chapters.
125126
It should be part of the front matter.
126127
\chapter{Preface}

src/tests/integration/inheritance-doc/expected/tex/main.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
\tableofcontents
122122

123123

124+
\cleardoublepage
124125
\begin{docstringBox}{structure}
125126
\LeanVerb|Verso.Integration.InheritanceDoc.FooExtends : Type|\tcblower Documentation for FooExtends\par\noindent\textbf{Constructor}\par \par \LeanVerb|Verso.Integration.InheritanceDoc.FooExtends.mk|\par\noindent\textbf{Extends}\par Verso.Integration.InheritanceDoc.FooExtends\par\noindent\textbf{Fields}\par \par \LeanVerb|barField1| : \LeanVerb|Bool|\par Inherited from \LeanVerb|BarExtended|\par \LeanVerb|barField2| : \LeanVerb|Unit|\par Inherited from \LeanVerb|BarExtended|\par \LeanVerb|fooField1| : \LeanVerb|Nat|\par Documentation for fooField1\par \LeanVerb|fooField2| : \LeanVerb|String|\par Documentation for fooField2
126127
\end{docstringBox}

src/tests/integration/sample-doc/expected/tex/main.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
\tableofcontents
122122

123123

124+
\cleardoublepage
124125
\begin{docstringBox}{def}
125126
\LeanVerb|Verso.Integration.SampleDoc.sample_constant : Type|\tcblower This is a docstring.Here's some more text with a \LeanVerb|code inline| in it.
126127
Here's when a \LeanVerb|code inline|

src/verso-manual/VersoManual.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ def emitTeX (logError : String → IO Unit) (config : Config) (text : Part Manua
373373
if config.verbose then
374374
IO.println s!"Saving {dir.join "main.tex"}"
375375
h.putStrLn (preamble text.titleString authors date packages.toList preambleItems.toList)
376-
-- \frontmatter is inserted by our hardcoded preamble
376+
-- \frontmatter is inserted by our hardcoded preamble before the ToC, so it doesn't get inserted
377+
-- here. If there's any text at the start of the front matter, then we need to clear it to a new
378+
-- recto page after the ToC
379+
unless frontText.all (·.isEmpty) do
380+
h.putStrLn "\\cleardoublepage"
377381
for b in frontMatter do
378382
h.putStrLn b.asString
379383
h.putStrLn "\n\\mainmatter"

src/verso/Verso/Doc.lean

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ public def Inline.other (container : genre.Inline) (content : Array (Inline genr
167167

168168
public def Inline.empty : Inline genre := .concat #[]
169169

170+
public def Inline.isEmpty : Inline genre → Bool
171+
| .text s => s.isEmpty
172+
| .concat xs => xs.attach.all fun ⟨x, _⟩ => x.isEmpty
173+
| .code .. | .linebreak .. | .image .. | .link .. | .math .. | .other .. | .footnote .. | .bold .. | .emph .. => false
174+
170175
public partial def Inline.rewriteOtherM [Monad m]
171176
(onInline :
172177
(Inline genre1 → m (Inline genre2)) →
@@ -446,6 +451,20 @@ public instance : Append (Lean.Doc.Block i b) where
446451

447452
public def Block.empty : Block genre := .concat #[]
448453

454+
public def Block.isEmpty : Block genre → Bool
455+
| .concat xs | .blockquote xs => xs.attach.all fun ⟨x, _⟩ => x.isEmpty
456+
| .para xs => xs.all (·.isEmpty)
457+
| .code .. | .other ..=> false
458+
| .ol _ xs | .ul xs => xs.attach.all fun ⟨⟨x⟩, _⟩ => x.attach.all fun ⟨y, _⟩ =>
459+
y.isEmpty
460+
| .dl xs => xs.attach.all fun ⟨⟨x, y⟩, _⟩ =>
461+
(x.attach.all fun ⟨x', _⟩ => x'.isEmpty) && (y.attach.all fun ⟨y', _⟩ => y'.isEmpty)
462+
decreasing_by
463+
all_goals (try decreasing_tactic)
464+
all_goals
465+
have := Array.sizeOf_lt_of_mem ‹_ ∈ xs›
466+
grind
467+
449468
public partial def Block.rewriteOtherM [Monad m]
450469
(onInline :
451470
(Inline genre1 → m (Inline genre2)) →

0 commit comments

Comments
 (0)