Skip to content

Add font family and size to the Markdown and LaTeX Visual editors - #828

Open
Tova22 wants to merge 42 commits into
ScientFactory:mainfrom
Tova22:editor-font-size
Open

Tova22 wants to merge 42 commits into
ScientFactory:mainfrom
Tova22:editor-font-size

Conversation

@Tova22

@Tova22 Tova22 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

Text > Font / Size in the Markdown and LaTeX Visual editors, same labels and order. Size is a number in points (1 to 100) with minus and plus buttons and a list of common sizes; it applies to the word under a caret, closes on Enter, and shows an empty field for a mixed selection, where minus and plus move each word by 1 pt. Mod+Shift+. and Mod+Shift+, (by key position) step the size. Fonts come from one catalogue, are shown in their own face in a searchable list that scrolls inside its panel. Document settings set the whole document's font and base size.

Storage: Markdown <span style="font-size:12pt"> and <span style="font-family:'Times New Roman'">, always outside bold, italic, strikethrough and links; front matter fontsize and mainfont. LaTeX {\fontsize{N}{M}\selectfont …}, \fontfamily{code}\selectfont or a guarded \fontspec; fix-cm added once for exact sizes in pdfLaTeX.

Whitespace rule (Markdown): a space or line break where the styles change carries no bold, italic, strikethrough, size or family, in the writer and in the round-trip guard. This also changes bold, italic and strikethrough: a space typed after a bold word and bold removed from the last word of a paragraph are no longer refused. Font commands skip inline code.

Exports: PDF keeps the exact forms through the sanitizer; Word gets one character style per used size and font ("12 pt", "Times New Roman 12 pt"), sizes rounded to half points, Hebrew through the complex-script font; a LaTeX document's base font and size follow its preamble (10 pt by default).

Why

Sizes by name and three generic families are too coarse for papers that must use a given font and size. Numbers in points match Word, PDF and LaTeX.

Documentation Impact

Updated: docs/user/markdown.md, docs/user/latex.md, docs/internals/scient-rich-markdown-editor.md.

UI Changes

Screenshots to add (light and dark, Markdown and LaTeX): the Font / Size panel.

Checklist

  • This PR is small and focused (it is not: 64 files, 5,269 added and 216 removed lines, kept as one PR because both editors and both exports share the catalogue)
  • I explained what changed and why
  • Screenshots to attach
  • No animation

Model and harness: Claude Sonnet 5.5 and Claude Opus 5.5, Claude Code.

🤖 Generated with Claude Code

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XXL labels Nov 10, 2026
@Tova22

Tova22 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Three small editor issues found while testing fonts (2026-11-10)

None looks caused by the font work, and we are not fixing them in the font PR. Issues 1 and 3 were reproduced with plain bold. Issue 2 was seen after a size change; I did not check it with bold.

1. Source gets blocked (Markdown)

Steps: type text in Source, go back to Rich, change that same text, go back to Source.

Result: "Source editing is paused to protect changes made in Rich." Returning to Rich does not help. Only reloading the page unblocks it. No text is lost.

Cause: Source keeps its own undo history, and Rich changed the same text, so Scient can no longer keep that history consistent. It blocks Source rather than risk damaging the text (FilePreviewPanel.tsx, restorationBlocked).

Option A: keep as is.
Option B (recommended): when this happens, drop Source's undo history and show the current Rich text. The user loses Source's Undo in that case, never the text.

Question: was the block deliberate?

2. Rich Undo resets after a Source round trip (Markdown)

Steps: Rich, then Source, then Rich again. The Undo button is greyed out: the history starts from zero.

Question: is this intended?

3. Undo button always greyed (LaTeX Visual)

Cmd+Z and Cmd+Shift+Z work. The toolbar Undo button stays greyed out, even after bold.

Question: should the button follow the history?

yaacovcorcos added a commit that referenced this pull request Nov 10, 2026
Trust the author of #828 (editor Font/Size menu) in the vouch workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yaacovcorcos yaacovcorcos mentioned this pull request Nov 10, 2026
2 tasks done
@yaacovcorcos

Copy link
Copy Markdown
Contributor

Thank you, Tova, this is careful work, and the PR description and the issue notes made it easy to review. The approach is right: it builds on the shared Text menu and on the size and family marks the LaTeX editor already had. The Markdown source ledger is a good fit for keeping untouched source exactly as it was.

We checked head 8e5b198855. Typecheck, vp check and knip pass locally, and so do the scient-markdown tests. The few web and server test failures we saw are in files this PR doesn't touch: two passed on re-run, and the rest come from our machine's setup. We checked each issue below against the code, and ran focused probes for source round trips and for the Pandoc conversion. We've opened #834 to add you to the vouch list. Once it merges, the vouch workflow will recheck your open PR.

Here is what needs fixing before merge. Each item comes with an example to reproduce it.

Needs fixing

1. Word export of LaTeX: some size groups break the export or lose their size
apps/server/src/scient/pandoc/pandocFont.ts:183 and :212 decide whether { starts a group by looking only at the character just before it.

  • \section {\large Intro} and Body\footnote {\small note}. (with a space before the brace) are rewritten to \section \ScientSize{…}{Intro}. Pandoc then fails the whole export with unexpected \textcolor. Without the rewrite, the same source exports fine.
  • a{\Large b}c and \textbf{x}{\large y} are skipped, so the size is silently lost in Word.

Suggestion: keep the group's own braces around the carrier ({\ScientSize{…}{…}}), and stop deciding "argument or group" from the one previous character. We checked with Pandoc 3.13 that keeping the braces fixes both failing examples and keeps the size.

2. Word export: the size rewrite reaches into inline verbatim
The rewrite skips verbatim environments but not \verb|…| or \lstinline. So \verb|{\large x}| comes out in Word as the literal text \ScientSize{scient-size-large}{x} (pandocFont.ts:180–205). Please skip inline verbatim bodies too.

3. Document settings can change front-matter lines the user didn't touch
apps/web/src/scient/markdownEditor/documentFont.ts:61 removes every font-size / font-family line and writes back only values the card recognises.

  • With font-size: 14pt (or font-size: 11pt # base size), changing only the Font deletes the size line.
  • With a multi-line value:
    title: Original
    font-family: |
      serif
    choosing a size leaves serif behind, and YAML now reads it as part of title.

Please update only the font key the user changed, keeping the other key's original value and comments. If a font value spans several lines and can't be rewritten safely, leave the block untouched and make that setting unavailable.

4. New front matter in a file whose first line is blank
apps/web/src/scient/markdownEditor/prosemirror/commands.ts:559 inserts the YAML block at document position 0, but the projection writes the ledger prefix (the leading blank line) first (projection.ts:532). For \nHello\n, choosing 11 pt saves \n---\nfont-size: 11pt\n---\n\nHello\n. That reopens as a horizontal rule and a heading "font-size: 11pt", not front matter.

Please write newly created front matter before the ledger prefix, keeping the original blank lines below it.

5. LaTeX Visual: a size on a selection that crosses math or bold loses a space
apps/web/src/scient/latex/latexFontCommands.ts:35 applies the mark to the selection, and each text node is wrapped on its own (latexTextFormatting.ts:71). Selecting "We see $x$ here" and choosing Larger writes {\large We see }$x${\large here}. The edit is accepted, but TeX (and the Visual parser) skip the space after \large, so on reopening, the space before "here" is gone.

Please keep a leading space when serialising each size-marked text node: both {\large{} here} and {\large\ here} keep it. Trimming the selection ends alone won't fix spaces inside the selection.

6. LaTeX Font: Default removes \familydefault lines it shouldn't
apps/web/src/scient/latex/latexDocumentLayoutSettings.ts:267–269 removes every matching \renewcommand{\familydefault} in the preamble, including ones inside comments and macro bodies. Removing one from a macro body changes what the document does. Please patch only the active top-level declarations, as the reader already does (:53–65).

7. Word sizes for LaTeX documents at 11pt and 12pt
apps/server/src/scient/pandoc/scientReferenceDocument.ts:412 multiplies the em ratio by the base size. The ratios are based on a 10pt class, so they don't follow LaTeX's 11pt and 12pt size tables. With \documentclass[11pt], \Large is 14.4pt in LaTeX and in the Visual editor, but 16pt in Word. At 12pt, \Huge is 24.88pt in LaTeX and 30pt in Word.

Please share the standard-class size table the Visual editor uses (latexVisualFontMetrics) as a plain module both sides can import. Use it for LaTeX Word output, allowing for Word's half-point steps, and keep the ratios for Markdown.

8. Nested font spans of the same kind show the wrong font
apps/web/src/scient/markdownEditor/prosemirror/schema.ts:599 / :832. For

<span style="font-family:serif">A <span style="font-family:monospace">B</span> C</span>

Rich shows " C" in the default font instead of serif, because opening the inner mark replaces the outer one and closing it removes both. In our tries, the saved source stayed safe: typing kept the original wrappers, and formatting changes were blocked by the source-fidelity guard. But the view is wrong. Please either restore the outer font when the inner span closes, or treat same-kind nested spans as source in both the ledger (packages/scient-markdown/src/sourceLedger.ts:143–163) and the tokenizer.

9. Docs
Please update the Markdown and LaTeX user guides on current main for Text > Font / Size, the new document font setting, and Markdown's front-matter keys. The LaTeX guide already covers the document text size and supported fonts. Please also remove the line in docs/internals/scient-rich-markdown-editor.md that says inline size controls aren't part of the editor.

Smaller points (fine as follow-ups)

  • The Word export reads the class size and the family default from commented-out lines too. A commented 12pt class overrides an active 11pt one (pandocFont.ts:238–239). The editor reads only active lines, and the export should do the same.
  • In Word, a size span inside a link's text replaces its blue, underlined character style. The link itself still works.
  • A font picked on a Markdown table-cell selection reaches only one of the selected cells (commands.ts:497–515 uses from/to instead of every cell range).

Your three questions

  1. Source paused after Source → Rich → Source. The refusal is a deliberate safeguard, and the same path exists on main. Source keeps its own undo history, and when Rich has changed the same text, Scient refuses to rebase that history rather than risk the text. MarkdownSourceSurface.dom.browser.test.tsx:508 tests that underlying refusal, without changing the source or the undo history. Staying paused until reload is a usability issue we'll handle separately. Your option B is a good candidate.
  2. Rich Undo resets after a Source round trip. The same limitation exists on main. Rich's history is rebuilt when its component remounts, because each mount creates a new controller (ScientMarkdownWorkspaceSurface.tsx:173–178) and only the source is kept. It's a separate fix, not for this PR.
  3. LaTeX Visual Undo button greyed. Yes, the button should follow the history. It reads can().undo() during render (LatexVisualEditor.tsx:9822). Automatic re-renders on transactions are off (:7297), and the manual refresh doesn't run after ordinary typing, so the button goes stale. The same code is on main, so this is a separate fix too.

Thanks again. Once the required fixes are in, we'll recheck them in the app before deciding whether it's ready to merge.

@yaacovcorcos

Copy link
Copy Markdown
Contributor

One more item for the list, on the front-matter key for the document size:

10. Please use fontsize instead of font-size
Pandoc, Quarto and R Markdown already read fontsize: 11pt (or 10pt or 12pt) as the document's base size. Many researchers' Markdown files already have that key. With font-size, Scient ignores their existing setting. If they then pick a size in Document settings, the file ends up with two keys that disagree: Scient uses one and their Pandoc or Quarto build uses the other.

Since the key hasn't shipped yet, please switch to fontsize everywhere it is read or written: apps/web/src/scient/markdownEditor/documentFont.ts (the reader at :35, the writer at :53 and FONT_KEYS at :18), and meta["font-size"] in apps/server/src/scient/pandoc/pandocFont.ts:125. Pandoc has no standard key for a generic serif / sans-serif / monospace choice, so font-family can stay as it is.

Tova22 and others added 23 commits November 16, 2026 10:30
- Shared Text > Font / Size menu: three generic families, ten sizes.
- Markdown: recognised <span style="font-size|font-family"> marks on a
  selection; front matter keys and a Document settings card for the
  whole document.
- LaTeX Visual: menu wired to the existing size and family marks; a
  Font field in Document settings (\familydefault).
- PDF export keeps the recognised span styles before sanitising.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Recognised Markdown <span style> forms become Word character styles
  (one per size, family, and size with family) before raw HTML is
  stripped; any other HTML is still dropped.
- The font-size and font-family front matter keys set the base font of
  the reference document; local sizes scale from that base.
- LaTeX: {\large ...} groups are rewritten to a form Pandoc keeps and
  mapped to the same styles; \textsf and \textrm are kept; the class
  option and \familydefault set the base font.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ut of command arguments

Found by an independent review. Pasted <span data-scient-font-*> values are now checked
against the known size and family names. The Word export no longer rewrites a size
command that is a command argument (\textbf{\large x}), nor verbatim or bracket math.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ont matter, share the document sizes

A local size inside a heading or a footnote is now a share of that text's size in the
Word export, as in the editor. Writing the document font no longer drops blank lines of
the front matter. The 10/11/12 pt sizes and the leading front matter pattern are defined
once. Added guards for tags inside code or links within a font span.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d test heading and footnote sizes with Pandoc

Found by a second independent review. A heading or a footnote now starts from its own size
and no outer font; the reference document cache key no longer depends on span order.
Added integration tests for sizes inside a heading and a footnote, and stricter unit tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sizes are free numbers of points (1 to 100) in both editors and in the Word
export; fonts come from one shared catalogue. Markdown stores
`font-size:12pt` and `font-family:'Times New Roman'`; LaTeX Visual stores
`{\fontsize{N}{M}\selectfont ...}` groups. Both editors share one FontControls
panel. The Word export defines one character style per used size and font.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…, Word export of font groups

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ink look and verbatim in the Word export; docs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…xports; test spaces around math

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… hidden closing tags stay source, fontspec package, document font card state

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ut presets

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…the selection toolbar

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ctions

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… familydefault

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… is open

The toolbar followed the selection, so it moved a little at every size step and
the buttons shifted under the pointer. Its position is now fixed while the size
panel is open and measured again when it closes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A space or line break where the set of styles changes carries no style, in the
writer (a space between two styled words no longer takes the open styles) and in
the round-trip guard, which also ignores spaces at paragraph ends and next to
line breaks. This applies to bold, italic, strike, size and family, and removes
most "would read back differently" refusals: typing a space after a styled
word, removing bold from the last word of a phrase, changing a size next to a
line break, sizing two bold words, edge spaces inside a tag.

Size and font commands skip inline code, which the reader cannot read back with
a span around it. The size and font shown for a selection ignore text made only
of spaces, so words sized one by one show their size.

Tests: directed cases, and a seeded gesture battery over 16 paragraph kinds
where only a known family (a delimiter touching a size tag inside a word) may
still be refused.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…-browser font gesture tests

The rule that edge whitespace carries no style also stripped the link mark from a space
between a link's plain and bold parts, splitting one link into three. Only the marks the
file cannot put around a space (em, strong, strike, size, family) are removed now.

fontGestures.browser.test.ts replays typing, Enter, bold and size gestures with real
keystrokes and checks no edit is refused.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Tova22 and others added 4 commits November 16, 2026 10:52
…phasis

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…onger gesture tests

An independent review found, and a run confirmed:
- turning inline code on over sized text was refused; it now drops the size and family;
- a combining accent ended up outside the sized word;
- the size shown for a selection counted inline code and read as mixed;
- the seeded gesture battery used a generator that produced almost only one command, so most
  gestures never ran; it now uses a spread generator, and its known-refusal list covers
  emphasis delimiters between a letter and punctuation (same refusal before this branch);
- two tests compared a text with its own reopening and checked nothing; they assert the text.
New tests cover links across bold, Hebrew, non-breaking space and inline code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eleting a line's first word

An audit ran the new tests against the code before the whitespace rule: 29 of 74 failed there,
but only 1 of the 9 browser tests did. Four browser tests now select with Shift+Arrow and type
with real keys under the conditions that failed before (a space beside a sized word, italic over
two sizes, bold removed from the last word, a size after a sized line break); they fail on the
old code. They wait for the editor to read the browser selection, which made one of them flaky
under load. A unit test records that deleting the first word of a line after a line break is
accepted, as at the start of a paragraph; refusing it would block a common gesture.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… under the caret

A size applied at a caret in "don't" or "l'arbre" covered only the part before the apostrophe.
A lone apostrophe still ends the word.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Tova22

Tova22 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

The branch is rebuilt on current main and force-pushed. The design differs from the reviewed version in three ways, so some items no longer apply as written.

Design

  • Sizes are numbers in points (1 to 100, two decimals), absolute, with minus and plus buttons. The ten names and the em ratios are gone.
  • Fonts come from one catalogue (packages/scient-markdown/src/fontCatalogue.ts), including Times New Roman. Markdown stores font-size:12pt and font-family:'Times New Roman'. LaTeX stores {\fontsize{N}{M}\selectfont …} and, for fonts, \fontfamily{qtm}\selectfont (pdfLaTeX) or a guarded \fontspec (XeLaTeX, LuaLaTeX).
  • Both editors use one panel (FontControls) under Text > Font / Size: a font button that opens a searchable, scrolling list, and a size row with a narrow field and borderless minus and plus buttons. No preset buttons.
  • At a caret, a size or font applies to the word under it. Enter in the size field, or choosing a font, closes the panel and keeps the selection. A selection that mixes sizes or fonts leaves the size field empty (fonts show "Mixed fonts"); the buttons then start from the document's base size. The Markdown selection toolbar has a size button that opens the same panel.
  • The LaTeX document font card (Document settings > Font) lists the same catalogue: \renewcommand{\familydefault}{qtm} under pdfLaTeX (fonts with a free look-alike; the others are greyed with a note), \setmainfont{…} with fontspec under XeLaTeX and LuaLaTeX.

Whitespace and the round-trip guard

  • Whitespace is not styled content. A space or line break where the set of styles changes carries no em, strong, strike, size or family. The writer and the round-trip guard (hasSameWritebackContent) use the same rule (unstyleBoundaryWhitespace in schema.ts). Links and code keep their spaces.
  • Effect on existing behaviour, beyond sizes and fonts: a space typed after a bold word, and bold removed from the last word of a paragraph, were refused ("would read back differently") before this rule and are accepted now.
  • A style the file cannot hold is not applied: font commands skip inline code, and turning inline code on over sized text drops the size and family.
  • When the size or font shown for a selection is computed, whitespace-only text and inline code are ignored, so words sized one by one show their common size.
  • roundTripBattery.test.ts replays seeded random gestures (size, family, bold, italic, typing, deletion) on 16 documents, 120 sequences each, and requires every refusal to belong to a known family: an emphasis delimiter touching a size tag inside a word, or between a letter and punctuation (the second is refused the same way before this branch).

Your items

  1. Fixed. The group keeps its own braces ({\ScientSize{…}{…}}), and the previous-character test is gone. \section {\large Intro}, Body\footnote {\small note}., a{\Large b}c and \textbf{x}{\large y} export (integration test, Pandoc 3.11).
  2. Fixed. \verb and \lstinline bodies are skipped (unit test).
  3. Fixed. Only the key you change is rewritten; other lines and trailing comments stay; a multi-line value makes the setting unavailable and the block untouched.
  4. Fixed. New front matter replaces the blank prefix, so it starts at byte 0 (test).
  5. Fixed by construction. One size group covers the whole run, with math and bold inside (test on We see $x$ here).
  6. Fixed. "Default" in the document font card removes only the active \familydefault declaration, using the same rule as the other settings there. Tests for a commented line and one inside a \newcommand body.
  7. Absent for numbers (absolute points). For the old \large-style names the Word export reads the 10, 11 or 12 pt table. It is a copy of latexVisualFontMetrics in the server, not a shared module. Question: where should the shared table live (an existing package, or a new one)?
  8. Fixed the second way you suggested: a span nested in a span of the same kind is left as source in the tokenizer (test). Different kinds still nest.
  9. Docs updated: docs/user/markdown.md, docs/user/latex.md, docs/internals/scient-rich-markdown-editor.md.
  10. Done: fontsize and mainfont (Pandoc and Quarto names).

Smaller points: commented class and family lines are no longer read by the Word export; a size inside a link keeps the link's blue underline (character style "14 pt link"); a size on a table cell selection reaches every selected cell (test).

My three questions of 2026-11-10 (Source paused, Rich Undo reset, LaTeX Undo button greyed): your answers are noted. This PR changes none of them; each stays a separate fix on main.

Open question for you

  • On a selection with words of different sizes, + today steps from the document's base size, which shrinks large text. Two options: + and − move to one step above the largest or below the smallest size present; or each word moves one step and keeps its difference, the field staying empty. Not implemented. Which one?

Checked (2026-11-16, on the rebased branch)

  • Formatting, lint, knip, typecheck (60 of 60 packages).
  • Unit and browser tests: src/scient/markdownEditor and src/scient/documentPage 1043 passed; packages/scient-markdown 397 passed.
  • Word export: apps/server/src/scient/pandoc 169 passed with the pinned Pandoc 3.11 (archive size and SHA-256 matched the manifest).
  • An independent review (a fresh reviewer given only the code and the specification) found: the seeded battery used a generator that produced almost only one command (replaced); inline code over sized text refused (fixed); a combining accent left outside the sized word (fixed); inline code counted when reading the shown size (fixed); two tests that asserted nothing (fixed). Each was reproduced by a run before being fixed.
  • Browser tests (Playwright) ran locally with Chromium 1248 through a link named 1223; 13 tests in fontGestures.browser.test.ts replay typing, Enter held, bold and size gestures with real keys; 5 of them fail on the code before the whitespace rule. Before commit b48dbbfc1d a run of the whole editor folder showed that the whitespace rule had split a link around bold text into three links; fixed in that commit, the existing test passes again.
  • Typing a space right before another space inserts a non-breaking space (U+00A0) in Chromium, also in plain text with no size; not caused by this work.
  • Real LaTeX compile with TinyTeX (earlier run): without fix-cm, pdfLaTeX rounds \fontsize (13 pt came out as 11.96 pt; 30 and 72 pt both about 24.8 pt). Scient adds \usepackage{fix-cm} once, only when a size is first written to a pdfLaTeX document that loads no scalable font package.
  • Dev app, by the author, on the branch before its last commit (which only changes caret word detection around apostrophes): size by word, space typed after sized and bold words, a link across bold text, inline code over sized text, an accented word, deleting the first word of a line after a line break, bold removed from the last word, Enter held after a sized word, mixed selection, font list, undo, light and dark, small window, PDF export. All as expected.

Known limits

  • Editing a paragraph that contains an inline HTML span in another shape (upper case, font-size: 14pt, single quotes, px, em, unknown font) shows it as source and rewrites < as \<. It happens with <b> too, so it predates this branch.
  • In the Markdown selection toolbar, applying bold or italic moves the toolbar; applying a size does not. Not established whether the bold and italic case predates this branch.
  • The Markdown and LaTeX Visual editors differ in two ways that predate this branch: Markdown has a collapsible formatting row and a floating selection toolbar with the size button; LaTeX Visual has a fixed row and only a citation toolbar. The Font / Size panel is the same through Text in both.
  • In LaTeX Visual an edge space stays inside the sized group (written {\fontsize…\selectfont{} text}); in Markdown it is written outside the span. Only the width of that space differs.
  • Markdown ignores spaces at the start of a line after a line break. The editor accepts them (as at the start of a paragraph) so that deleting a line's first word is not refused; the space is written but not rendered. Before this branch such edits were refused. Refusing them again was tried: it blocks that deletion (3 refusals in 120 random sequences on a line-break document).
  • The whitespace rule uses JavaScript \s, which also matches U+FEFF, U+2028, U+2029, vertical tab and form feed; Markdown does not treat those as whitespace, so a paragraph that uses U+FEFF as a separator can still be refused.
  • Letters outside the basic plane (rare scripts, mathematical letters) split at the caret when a size is applied to the word under it. An apostrophe between two letters ("don't") belongs to the word.
  • Bold applied over inline code that has edge spaces splits the code into three code spans (text unchanged).
  • One shape still refused in fuzzing: an emphasis run, a line break, then a differently styled space (3 in 40,000 random paragraphs).
  • The Markdown size popover can cover the edited text when the floating toolbar sits above the first line.
  • Helvetica and Arial share one pdfLaTeX family, so Helvetica reopens as Arial.
  • Switching a XeLaTeX document with named fonts to pdfLaTeX is not guarded.
  • 44 LaTeX browser tests (11 files, src/scient/latex/*.browser.test.tsx, mostly 30 s timeouts) fail on this machine; 45 failed on the code before the whitespace commit. Not run on main alone; cause not established.

Not verified

  • Word: a .docx opened in real Word.
  • Windows, Linux, Tectonic.
  • The document-wide font written by the new card was not compiled; under XeLaTeX a font that is not installed makes the compile fail, as with the existing Main font field.
  • Keyboard shortcuts for the size are not implemented.
  • In pdfLaTeX documents only fonts with a free package look-alike are offered; the others are listed, disabled, with a note.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR changes the test suite by +145 test cases (browser +25, unit +83, server +37).

New browser test files: apps/web/src/scient/latex/latexFontCommands.browser.test.ts, apps/web/src/scient/markdownEditor/prosemirror/fontGestures.browser.test.ts, apps/web/src/scient/writing/FontControls.browser.test.tsx.
Each browser test file costs CI seconds of module loading before its first test runs; a unit test costs milliseconds.

Keep tests that would fail for a real reason, and test logic below the UI where it can be. See Testing.

Tova22 and others added 15 commits November 20, 2026 11:11
…r starts fast

The LaTeX Visual worker imported the whole Markdown package (parsers
included) through latexTextFormatting.ts, and the LaTeX browser tests
timed out waiting for it. A ./fonts entry exports only the font
catalogue and span forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the Word export

The base font now follows what the Document settings card writes:
a catalogue font code in \familydefault (pdfLaTeX) or a catalogue
font in \setmainfont (XeLaTeX, LuaLaTeX). A document without a class
size option is 10 pt, as in LaTeX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h editors

LaTeX Visual counted the spaces between words sized one by one, so it
showed no size, and its caret word stopped at apostrophes and
combining accents. Both editors now use writing/fontTarget.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its difference

As in Word, each run of a selection moves by one point and the size
field stays empty; text without a size starts from the size it is
drawn at, so a heading word grows from the heading's size. The panel
no longer needs the document's body size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bold, italic or strike delimiter touching a span tag inside a word
was misread by CommonMark, so the edit was refused. With size and font
first in mark rank, the gesture battery's refusals go from 111 to 91
per 36,500 gestures (the 20 tag cases are gone; the rest are formulas
and an unrelated nested-list deletion). The battery no longer allows
that family.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rtcuts

A click in the size field lists Word's sizes (8 to 72) under it, like
the font list; choosing one applies it and closes the panel. Mod+>
and Mod+< (Cmd+Shift+. and Cmd+Shift+, on a US keyboard) step the size
in both editors, with the same per-word rule as the minus and plus
buttons. No existing app, editor or menu shortcut uses these keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Pandoc

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, links whole

Rank alone did not decide nesting: the serializer reorders mixable
marks to fit those already open, so a size inside a bold part of a
word was written inside the delimiters and refused. Font marks are no
longer mixable. Links rank first, so a partly sized link stays one
link with the span inside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…own size

The buttons stepped every run per word only on a mixed selection;
over a heading and a paragraph without explicit sizes they set one
measured size. They now always go through the per-run rule, shared by
both editors (steppedRuns in fontTarget.ts), with Alt for 0.5 pt and
Shift for 10 pt; the field no longer re-commits its unchanged value
after a step. The drawn size is read inside the run, so it no longer
depends on where the selection starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…text

A catalogue font in \setmainfont (options allowed) now wins over a
font code in \familydefault and over \rmdefault; a sans-serif or
monospace \familydefault still wins over both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…icked

Stepping the size in Markdown gave focus back to the editor, so the
selection toolbar's size panel closed after one click. Focus now stays in
the panel, as in LaTeX Visual. The test also checks Alt (0.5 pt) and
Shift (10 pt) on the plus button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… whole

Only the line break or space next to a style change lost the size, bold,
italic or strike, so deleting the text before two sized line breaks wrote
the second one inside the span and the edit was refused. The rule now
repeats until the whole run of whitespace is outside.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… position

On macOS, Cmd+Shift reports the unshifted character, so the bindings on
">" and "<" never matched on a Mac (Cmd+Shift+, even reached Cmd+,).
Writing strokes now name punctuation by its physical key under Ctrl, Cmd
or Alt, as they already did for digits and as the app's own shortcuts do.
The tests send the events a Mac sends, including a French layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tova22

Tova22 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Corrections before merge, pushed on the same branch (15 commits after b5eef10; still based on main at 301abac, not rebased).

Fixes

  • LaTeX browser tests: 44 of 560 failed on this branch and none on its base. Cause: latexTextFormatting.ts imported @scientfactory/scient-markdown, so the LaTeX Visual worker (visualProcessing.worker.ts) loaded the whole Markdown package, parsers included, and the tests timed out waiting for it. The package now has a light ./fonts entry (catalogue and span forms only), used by the LaTeX and writing files. 560 of 560 pass.
  • Word export of a LaTeX document now reads the font the Document settings card writes (\renewcommand{\familydefault}{qtm} under pdfLaTeX, \setmainfont{…} under XeLaTeX and LuaLaTeX, catalogue fonts only, preamble only), and uses 10 pt when the class has no size option, as LaTeX does (it used 11 pt).
  • One rule for both editors (apps/web/src/scient/writing/fontTarget.ts): the word under the caret (accents and an apostrophe between letters included) and the size or font shown for a selection (spaces and inline code ignored). LaTeX Visual counted the spaces between words sized one by one, so it showed no size; it also cut words at apostrophes and combining accents. Reproduced in a real browser before the fix.
  • Size and font spans are written outside bold, italic and strikethrough in Markdown (un**be**<span style="font-size:14pt">**lie**</span>**v**able), and inside links, so a partly sized link stays one link ([a<span …>b</span>c](url)). A delimiter touching a span tag inside a word was refused by the round-trip guard. The font marks come right after the link in mark rank and are no longer mixable (the serializer reorders mixable marks to fit those already open, which put the span back inside). On the seeded gesture battery (29 kinds of paragraph, about 36,500 gestures) refusals go from 111 to 91: the 20 span cases are gone; the rest are formulas and one case unrelated to fonts (deleting the whole first item of a nested list, 85). Six direct tests cover a size cut inside bold, italic, strike, a link and a family; five of them fail on the previous code. roundTripBattery.test.ts no longer allows the span family.
  • In Markdown, the selection toolbar's size panel closed after one click on plus or minus (the step gave focus back to the editor); it now stays open, as in LaTeX Visual.
  • A run of two line breaks where a size starts was only half moved out of the span, so deleting the text before them was refused. The whitespace rule now applies to the whole run.

Answer to my own open question

  • + and − now move each run of the selection by 1 pt (Alt 0.5 pt, Shift 10 pt), so words keep their differences, as in Word; on a mixed selection the field stays empty. Text without a size starts from the size it is drawn at, so a heading word grows from the heading's size. The rule is shared by both editors (steppedRuns in fontTarget.ts).

Known limits added

  • The size list opens with the mouse; from the keyboard, type the number (Alt+Down already steps 0.5 pt).
  • Typing the number already shown does not set an explicit size.

Additions

  • A click in the size field lists common sizes (8 to 72, Word's list) under it, like the font list; choosing one applies it and closes the panel. No new button.
  • Mod+Shift+. and Mod+Shift+, step the size in both editors, with the same rule as the buttons. They are matched by key position, as the app's own shortcuts are (EVENT_CODE_SHORTCUT_KEYS): on macOS, Cmd+Shift reports the unshifted character, so a binding on > never matched on a Mac. eventStroke now names punctuation by its physical key under Ctrl, Cmd or Alt, as it already did for digits; this also applies to Mod+\ (clear formatting) and to shortcuts recorded in Settings. No app default (packages/shared/src/keybindings.ts), Electron menu accelerator or editor shortcut uses these keys.

Checked (2026-11-22, on the branch head 56b4d68)

  • Formatting, lint, knip, typecheck.
  • LaTeX browser tests (src/scient/latex): 566 of 566.
  • Browser tests of src/scient/markdownEditor, documentPage, writing, keyboard: 511 of 511. Unit tests of apps/web/src/scient: 4,043 of 4,043. packages/scient-markdown: 397 of 397 (2026-11-20; the package is unchanged since).
  • In the app: the size panel, Alt and Shift on plus, both shortcuts in Markdown and LaTeX on a French keyboard, and a Hebrew document.
  • Word export: apps/server/src/scient/pandoc 173 of 173 with the pinned Pandoc 3.11 (archive size and SHA-256 matched the manifest), including a new test for the card's font at 10 pt (2026-11-20; the server code is unchanged since).
  • Real compile with the pinned TinyTeX 2026.08: a Hebrew document from the Hebrew template under XeLaTeX, with an 18 pt group, a Times New Roman group and a 9 pt Courier New group, written by the editor's own functions; compiled, right to left, no missing glyph, Courier New and Times New Roman embedded. An English pdfLaTeX document with Palatino set by the card and a Helvetica group compiles with TeX Gyre Pagella and Heros once the tex-gyre package is installed.
  • An independent review (code and specification only) found, each reproduced before the fix: size tags still written inside emphasis within a word (the mixable point above); the buttons stepping per word only on a mixed selection, so a heading and a paragraph without sizes got one size; the Word base font chosen by catalogue order instead of the declaration that sets the text, and \setmainfont[options]{…} not read; the drawn size depending on where the selection starts. All fixed with tests that fail on the previous code.

Found, not fixed (your call)

  • In a Hebrew document (XeLaTeX, polyglossia), the font chosen in Document settings does not reach Hebrew text: \hebrewfont from the language setup wins. The Word export shows the chosen font.
  • Under pdfLaTeX, catalogue fonts (\fontfamily{qtm}, \renewcommand{\familydefault}{qpl}) need the tex-gyre package. Without it LaTeX only warns ("Font shape T1/qpl/m/n' undefined") and uses Computer Modern. The missing-package detection installs packages on "File not found" only, so a fresh managed TinyTeX never gets tex-gyre. Options: map that warning to tex-gyre`, or include it in the managed install.
  • With the pinned TinyTeX 2026.08, tlmgr install first asked for tlmgr update --self against the default repository (seen on a scratch copy, not checked in the app).
  • The Word export keeps its own copies of the LaTeX font declaration patterns and the generic family map (pandocFont.ts, next to latexDocumentLayoutSettings.ts); same question as item 7 of your review: where should shared LaTeX tables live?

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. and removed vouch:unvouched Author is not yet trusted in the VOUCHED list. labels Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants