Conversation
The spacing setting only controlled section/subsection header spacing, not actual line spacing. This adds baselineskip control so 'tiny' actually reduces line spacing significantly.
- Add baselineskip values to SPACING_MAP (6pt/8pt/11pt/14pt for tiny/small/medium/large)
- Add \setlength{\baselineskip}{X} to dynamic header generation
- Update formula_gap extraction to handle 6-element tuple
- Make tiny spacing truly tiny (baselineskip 4pt vs 6pt) - Fix recompile to apply current layout options (columns, fontSize, spacing, margins) - Add 4-column option to dropdown and backend validation - Add proper React dependencies to handleCompileOnly
…ns to bottom - Backend: generate-sheet now returns valid LaTeX even with empty formulas (for recompile) - Frontend: recompile (middle circle button) now regenerates with current layout options - Add 4-column option to dropdown - Move LayoutOptions from top selection panel to bottom editor panel - Update tests for new empty formulas behavior
Previously recompile replaced entire content with empty formula template, causing empty document error. Now it extracts the body from existing content and merges with new layout header.
- LayoutOptions now appears at top of editor/preview panel (above LaTeX editor)
- Simplify merge logic to extract and preserve document body
- Fix missing \end{document} in merged output
The old merge logic kept the old multicols wrapper which overrode the new column count. Now it extracts just the formula content from the old body and inserts it into the new layout's multicols environment, preserving the new column/spacing settings.
There was a problem hiding this comment.
Pull request overview
This PR enhances the LaTeX cheat sheet generator’s layout flexibility and frontend/backend integration, adding support for 4 columns, new spacing controls, and improved handling of “no formulas selected” requests.
Changes:
- Extend layout options (backend validation + frontend UI) to support up to 4 columns.
- Add/propagate new LaTeX spacing behavior (including
\baselineskip) and tweak formula rendering. - Update API + frontend to handle empty selections more gracefully and to regenerate LaTeX templates when layout options change.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/hooks/latex.js | Regenerates LaTeX template on layout changes before compiling to keep preview aligned. |
| frontend/src/components/CreateCheatSheet.jsx | Adds 4-column option and reorganizes layout controls vs editor/preview panels. |
| backend/api/views.py | Allows up to 4 columns; returns empty-but-valid LaTeX when no formulas are selected. |
| backend/api/tests.py | Updates generate-sheet endpoint tests to expect 200 + tex_code for empty/missing formulas. |
| backend/api/latex_utils.py | Adds baselineskip to spacing presets and updates LaTeX generation (header + formula rendering). |
| .opencode/opencode.json | Adds OpenCode plugin configuration file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| f"\\titlespacing*{{\\section}}{{0pt}}{{{sec_before}}}{{{sec_after}}}", | ||
| f"\\titlespacing*{{\\subsection}}{{0pt}}{{{subsec_before}}}{{{subsec_after}}}", | ||
| f"\\setlength{{\\baselineskip}}{{{baseline_skip}}}", | ||
| "", | ||
| "\\begin{document}", | ||
| size_command, |
There was a problem hiding this comment.
\setlength{\baselineskip}{...} is set before \begin{document} and before applying the selected font size command. In LaTeX, changing font size (e.g. \footnotesize/\tiny) typically resets \baselineskip, so this line may have no effect. Consider applying the baselineskip after the size command (or using \AtBeginDocument / \fontsize{...}{...}\selectfont) so the spacing preset actually takes effect.
backend/api/latex_utils.py
Outdated
| body_lines.append("\\textbf{" + escaped_name + "}") | ||
| body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{\\displaystyle " + latex + "} \\]") | ||
| body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{$" + latex + "$} \\]") | ||
| body_lines.append(f"\\\\[{formula_gap}]") |
There was a problem hiding this comment.
This wraps the formula in
| const multicolMatch = oldBody.match(/\\begin\{multicols\}\{(\d+)\}([\s\S]*?)\\end\{multicols\}/); | ||
|
|
||
| let formulaContent = oldBody; | ||
| if (multicolMatch) { | ||
| formulaContent = multicolMatch[2]; |
There was a problem hiding this comment.
The multicolumn body extraction captures everything after the column count, which includes template scaffolding like \raggedcolumns. When you later prepend the regenerated template's own content, this can duplicate \raggedcolumns (and any other boilerplate inside the multicols block), making the merged LaTeX inconsistent. Consider extracting only the user-authored portion (e.g., strip leading \raggedcolumns/blank lines) before reinserting.
frontend/src/hooks/latex.js
Outdated
|
|
||
| contentToCompile = newParts[0] + '\\begin{multicols}' + columnCount + '}' + beforeEnd + formulaContent + '\\end{multicols}' + afterEnd; | ||
| } else { | ||
| contentToCompile = newLatex; | ||
| } |
There was a problem hiding this comment.
If the regenerated template does not contain a multicols environment (e.g. columns === 1), this branch sets contentToCompile = newLatex, which discards the existing document body/formulas entirely and results in compiling an empty sheet. The merge logic should handle the no-multicols case by preserving the old document body and injecting it into the regenerated header/footer (or wrapping/unwrapping multicols appropriately when toggling between 1 and >1 columns).
| f"\\setlength{{\\baselineskip}}{{{baseline_skip}}}", | ||
| "", | ||
| "\\begin{document}", | ||
| size_command, |
There was a problem hiding this comment.
The new baselineskip behavior isn’t covered by existing API tests (e.g., test_generate_sheet_with_spacing only asserts that titlespacing exists). Consider adding an assertion that the generated LaTeX includes the expected \setlength{\baselineskip}{...} for a given spacing preset, so regressions in spacing presets are caught.
This pull request introduces several improvements to the LaTeX cheat sheet generator, focusing on layout flexibility, LaTeX spacing customization, and a more robust API/frontend integration. The main updates include support for up to 4 columns, enhanced LaTeX spacing controls, and improved handling of cases where no formulas are selected. Additionally, the frontend now dynamically regenerates LaTeX headers/footers when layout options change, ensuring the preview always matches user selections.
Layout and Customization Enhancements:
validate_layout_paramsinbackend/api/views.py) and frontend options (LayoutOptionsinfrontend/src/components/CreateCheatSheet.jsx). [1] [2]SPACING_MAPto include abaselineskipvalue, allowing for more granular control over line spacing in the generated document (backend/api/latex_utils.py).\baselineskipaccording to the selected spacing preset (build_dynamic_headerinbackend/api/latex_utils.py). [1] [2]API and Logic Improvements:
/api/generate-sheet/endpoint to return a valid (empty) LaTeX document with a 200 status code when no formulas are selected, instead of returning a 400 error. Corresponding tests were updated to reflect this behavior (backend/api/views.py,backend/api/tests.py). [1] [2]$... within the\adjustboxfor better compatibility (build_latex_for_formulasinbackend/api/latex_utils.py`).Frontend Integration:
useLatexinfrontend/src/hooks/latex.js). [1] [2]frontend/src/components/CreateCheatSheet.jsx). [1] [2]Other:
.opencode/opencode.jsonconfiguration file for plugin support.