frontend: centre the display formula, and let one be set left or right

Display formulas were sitting against the left margin with only their number at
the right, and the cause was a rule I had written myself: the paragraph's
stylesheet set `text-align: left` on `.katex`, which is the very element KaTeX
centres a display formula in. A well-meant attempt to keep a formula from being
justified apart had quietly overridden the centring, and it applied to every
formula in every paper — measured on a paragraph of known width, the formula's
midpoint sat 607px left of centre.

The override is gone; the rule carries only a font size now, and a comment says
why nothing about alignment belongs there.

`paper_sentence.formula_align` then adds the choice the writer asked for: a
display formula can be `center` (the default, and what a paper wants almost
always), `left` or `right`. It is per sentence rather than a template-field
setting — one paragraph legitimately mixes a centred equation with a
right-aligned continuation, and a field describes a heading, not a formula — and
the paragraph editor offers it only on rows that contain display maths, since
only those have a line of their own. The equation number is untouched: `\tag{1}`
prints against the right margin in all three cases, as every numbered style
does.

Measured in the browser on a 1276px paragraph: centred puts the formula 596px
from each edge, left puts it at 0, right puts it at 1225, and the tag is at the
right in every case. 56 paper checks (2 new: the round trip and the refusal of
an alignment the renderer does not know), 61 reference checks, 99 MCP checks,
`vue-tsc` and the build all pass.
This commit is contained in:
2026-09-23 13:14:52 +08:00
parent c65efa32ac
commit e8e129221c
9 changed files with 228 additions and 18 deletions
+41 -9
View File
@@ -302,7 +302,39 @@ def main() -> int:
)
call("PUT", f"/papers/{paper['id']}/paragraphs/{second_sort}", {"sentences": []})
print("9. reject a citation with no quote")
print("9. a formula says how it is set on its line")
aligned = call(
"PUT",
f"/papers/{paper['id']}/paragraphs/{second_sort}",
{
"sentences": [
{"content": "$$ E = mc^2 $$", "formula_align": "right"},
{"content": "$$ F = ma $$", "formula_align": "left"},
{"content": "$$ p = mv $$"},
]
},
)
paragraph_aligned = next(
p
for p in aligned["paragraphs"]
if p["paper_template_filed_sort"] == second_sort
)
check(
"alignment is stored per sentence, defaulting to centre",
[s["formula_align"] for s in paragraph_aligned["sentences"]]
== ["right", "left", "center"],
str([s["formula_align"] for s in paragraph_aligned["sentences"]]),
)
call(
"PUT",
f"/papers/{paper['id']}/paragraphs/{second_sort}",
{"sentences": [{"content": "$$ x $$", "formula_align": "middle"}]},
expect=422,
)
check("an alignment the renderer does not know is refused", True)
call("PUT", f"/papers/{paper['id']}/paragraphs/{second_sort}", {"sentences": []})
print("10. reject a citation with no quote")
bad = call(
"PUT",
f"/papers/{paper['id']}/paragraphs/{first_sort}",
@@ -320,7 +352,7 @@ def main() -> int:
)
check("citation without content refused", "detail" in bad)
print("10. a sentence with no paragraph in the template survives a switch")
print("11. a sentence with no paragraph in the template survives a switch")
# A position neither template defines, so the check means the same
# thing before and after the switch below.
orphan_sort = (
@@ -348,7 +380,7 @@ def main() -> int:
p for p in document["paragraphs"] if p["paper_template_filed_sort"] == orphan_sort
)["name"] is None)
print("11. switch the template")
print("12. switch the template")
switched = call("PATCH", f"/papers/{paper['id']}", {"template_id": narrow["id"]})
check("template changed", switched["template_id"] == narrow["id"])
document = call("GET", f"/papers/{paper['id']}/document")
@@ -378,7 +410,7 @@ def main() -> int:
),
)
print("12. move one paragraph onto another position")
print("13. move one paragraph onto another position")
document = call(
"PUT",
f"/papers/{paper['id']}/paragraphs/{orphan_sort}",
@@ -393,18 +425,18 @@ def main() -> int:
all(p["paper_template_filed_sort"] != orphan_sort for p in document["paragraphs"]),
)
print("13. paper list reports progress")
print("14. paper list reports progress")
listing = call("GET", f"/papers?keyword=冒烟&status=writing")
check("found by keyword and status", listing["total"] == 1, str(listing["total"]))
row = listing["items"][0]
check("paragraph count", row["paragraph_count"] == 1, str(row["paragraph_count"]))
check("sentence count", row["sentence_count"] == 3, str(row["sentence_count"]))
print("14. a template in use cannot be deleted")
print("15. a template in use cannot be deleted")
conflict = call("DELETE", f"/templates/{narrow['id']}", expect=409)
check("template delete refused", "正被论文使用" in conflict["detail"], conflict["detail"])
print("15. single sentence edit and delete")
print("16. single sentence edit and delete")
sentence_id = target["sentences"][0]["id"]
updated = call(
"PATCH",
@@ -420,7 +452,7 @@ def main() -> int:
sum(len(p["sentences"]) for p in document["paragraphs"]) == 2,
)
print("16. a paper with no template still works")
print("17. a paper with no template still works")
bare = call(
"POST",
"/papers",
@@ -443,7 +475,7 @@ def main() -> int:
call("DELETE", f"/papers/{bare['id']}", expect=204)
created_papers.remove(bare["id"])
print("17. delete the paper")
print("18. delete the paper")
call("DELETE", f"/papers/{paper['id']}", expect=204)
created_papers.clear()
for reference_id in created_references: