frontend: typeset the LaTeX, and let a sentence start a new line

Two things a paper needs that the paragraph model could not express.

**Formulas.** A sentence stores the LaTeX the writer typed — `$\ell$`,
`$$ … \tag{1} $$` — because that is the editable form, and it was being printed
as source. `src/utils/math.ts` now splits a sentence into text and formulas,
gives the formulas to KaTeX and escapes everything else; `math-error` in red
when KaTeX cannot read one, rather than an exception that blanks the paragraph
(the paper in the database has 106 sentences with formulas, 29 of them
display). Four delimiters are recognised — `$$…$$`, `\[…\]`, `$…$`, `\(…\)` —
and an unmatched `$` is left alone instead of swallowing the rest of the
paragraph. A display formula is a block, so it takes its own line and centres
itself without any flagging; text goes through `v-html` escaped, and KaTeX runs
with trust off.

**Line breaks.** A paragraph is its sentences run together, which is right for
prose and wrong for a display formula, a list of items or an author line.
`paper_sentence.line_break_before` is that request: a flag rather than a
newline inside `content`, because content folds its whitespace on purpose (a
sentence really is one line) and because a break hidden in a string is one
nobody can see or remove. It prints a `<br>`, it is a checkbox on the
sentence's row in the editor, and it *replaces* the separator rather than
adding to it — the new line already separates, and a space as well would indent
the line by a blank.

Verified against the real paper in the browser: 214 inline formulas and 29
display formulas typeset with zero failures and no `$$` left on the page; a
sentence flagged for a break lands on its own line while its neighbour stays
inline; the display formula centres on a line of its own and the sentence after
it starts below. 54 paper checks (2 new), 61 reference checks and 76 MCP checks
pass, with `vue-tsc` and the build clean.

Also: `.pnpm-store/` is ignored — pnpm put its content-addressed store in the
project root rather than the home directory.
This commit is contained in:
2026-09-23 11:30:29 +08:00
parent b97aab6f30
commit 960450f744
14 changed files with 406 additions and 22 deletions
+11 -1
View File
@@ -419,7 +419,13 @@ def build_document(db: Session, paper: Paper) -> PaperDocumentRead:
# than by whoever prints them, so a reader, an export and a preview
# cannot each invent their own spacing.
for earlier, later in zip(sentences, sentences[1:]):
later.separator_before = sentence_separator(earlier.content, later.content)
later.separator_before = (
""
if later.line_break_before
# A line break already separates the two, and printing a space
# as well would indent the new line by one blank.
else sentence_separator(earlier.content, later.content)
)
paragraph = ParagraphRead(
paper_template_filed_sort=position,
@@ -678,6 +684,7 @@ def replace_paragraph(
paper_template_filed_sort=target,
sort=item.sort if item.sort is not None else base + offset,
content=item.content,
line_break_before=item.line_break_before,
citations=_build_citations(item.citations),
)
)
@@ -700,6 +707,7 @@ def append_sentence(db: Session, paper: Paper, data: SentenceCreate) -> PaperSen
paper_template_filed_sort=data.paper_template_filed_sort,
sort=sort,
content=data.content,
line_break_before=data.line_break_before,
citations=_build_citations(data.citations),
)
db.add(sentence)
@@ -729,6 +737,8 @@ def update_sentence(
sentence.paper_template_filed_sort = data.paper_template_filed_sort
if data.content is not None:
sentence.content = data.content
if data.line_break_before is not None:
sentence.line_break_before = data.line_break_before
if data.citations is not None:
sentence.citations.clear()
db.flush()