Add linear algebra#76
Conversation
There was a problem hiding this comment.
Pull request overview
This PR expands the cheat-sheet formula catalog by adding Linear Algebra I/II content, and also introduces an orientation layout option that flows from the frontend layout controls through backend LaTeX generation/normalization.
Changes:
- Add new Linear Algebra I and II formula datasets and register them in the formula catalog.
- Add
orientationas a persisted layout option in the frontend hook/UI and backend API/model. - Update LaTeX generation/normalization to include paper/orientation options, and adjust backend/frontend tests accordingly.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/hooks/latex.test.jsx | Extends hook tests to cover the new orientation default and custom value. |
| frontend/src/hooks/latex.js | Adds orientation state, persistence (localStorage), and API payload wiring for compile/normalize/generate calls. |
| frontend/src/components/CreateCheatSheet.jsx | Adds an Orientation selector to layout controls and plumbs orientation state into the UI. |
| backend/api/views.py | Accepts/validates orientation in generate/compile endpoints and returns it in normalize-only responses. |
| backend/api/tests.py | Updates/extends tests for new layout comment and updated LaTeX header expectations. |
| backend/api/models.py | Adds orientation field to CheatSheet. |
| backend/api/migrations/0008_cheatsheet_orientation.py | DB migration to add the orientation column with a default. |
| backend/api/latex_utils.py | Threads orientation through LaTeX header/layout-comment generation and normalization logic. |
| backend/api/formula_data/linear_algebra_i.py | Adds Linear Algebra I formulas. |
| backend/api/formula_data/linear_algebra_ii.py | Adds Linear Algebra II formulas. |
| backend/api/formula_data/init.py | Registers Linear Algebra I/II into available classes and formula data mappings. |
Comments suppressed due to low confidence (1)
backend/api/views.py:376
- When compiling via
cheat_sheet_id, the view overwrites columns/font_size/margins/spacing from the saved CheatSheet but does not overwriteorientation. This means a saved landscape sheet will still compile as portrait unless the client redundantly sendsorientation. Setorientation = cheatsheet.orientation(and consider re-runningvalidate_layout_paramsafter loading the model values) so the stored layout is consistently respected.
if cheat_sheet_id:
cheatsheet = get_object_or_404(CheatSheet, pk=cheat_sheet_id, user=request.user)
columns = cheatsheet.columns
font_size = cheatsheet.font_size
margins = cheatsheet.margins
spacing = cheatsheet.spacing
content = cheatsheet.build_full_latex()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| setSpacing, | ||
| margins, | ||
| setMargins, | ||
| orientation, | ||
| setOrientation, | ||
| pdfBlob, |
There was a problem hiding this comment.
orientation is now part of the layout state, but it is not included in the onSave(...) payloads (both the autosave snapshot and the explicit Save handler). As a result, the new orientation setting won’t persist across reloads/restores even though the UI exposes it. Include orientation (and, if applicable, in compileSnapshot) wherever layout settings are saved.
| columns = models.IntegerField(default=4) | ||
| margins = models.CharField(max_length=20, default="0.15in") | ||
| font_size = models.CharField(max_length=10, default="9pt") | ||
| spacing = models.CharField(max_length=10, default="small") | ||
| orientation = models.CharField(max_length=20, default="portrait") | ||
| # Stores selected formulas with user-defined order: [{"class": "...", "category": "...", "name": "..."}] |
| # 1. Force the PDF driver to rotate by passing landscape and letterpaper to the document class | ||
| doc_options = f"{doc_class_size},fleqn,letterpaper" | ||
| if orientation == "landscape": | ||
| doc_options += ",landscape" | ||
|
|
||
| # 2. Also pass them to the geometry package | ||
| geometry_options = f"letterpaper,margin={margins}" | ||
| if orientation == "landscape": | ||
| geometry_options += ",landscape" |
| @api_view(["POST"]) | ||
| def generate_sheet(request): | ||
| """ | ||
| POST /api/generate-sheet/ | ||
| Accepts { "formulas": [...], "columns": 4, "font_size": "9pt", "margins": "0.15in", "spacing": "small" } | ||
| Accepts { "formulas": [...], "columns": 4, "font_size": "9pt", "margins": "0.15in", "spacing": "small", "orientation": "portrait" } | ||
| Each formula: { "class": "ALGEBRA I", "category": "Linear Equations", "name": "Slope Formula" } | ||
| Or for special classes (like UNIT CIRCLE): { "class": "UNIT CIRCLE", "name": "Unit Circle (Key Angles)" } | ||
| Returns { "tex_code": "..." } |
There was a problem hiding this comment.
PR title/description focus on adding Linear Algebra content, but this PR also introduces a new layout feature (orientation) and changes LaTeX paper options (letterpaper) across compile/generate flows. Please update the PR description/title to reflect this additional user-facing behavior, or split the layout work into a separate PR for clearer review/release notes.
|
@copilot apply changes based on the comments in this thread |
…, and landscape test Agent-Logs-Url: https://github.com/ChicoState/cheat-sheet/sessions/feaa4cd4-4709-4685-85f7-54a23f49946e Co-authored-by: Davictory2003 <68972845+Davictory2003@users.noreply.github.com>
Applied all four changes from the review thread in commit 8a449ba:
All 99 backend and 53 frontend tests pass. |
level 1 and 2 linear algebra is now in play