-
Notifications
You must be signed in to change notification settings - Fork 3
Fix/spacing investigation #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
065b09a
961dcb8
d1da61b
00e34e0
a2d17c6
f8f1534
10baf60
e57bb09
f82b586
96503f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "$schema": "https://opencode.ai/config.json", | ||
| "plugin": [ | ||
| "oh-my-openagent" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,12 +33,12 @@ | |
| "12pt": "\\normalsize", | ||
| } | ||
|
|
||
| # Spacing presets: (section_before, section_after, subsection_before, subsection_after, formula_spacing) | ||
| # Spacing presets: (section_before, section_after, subsection_before, subsection_after, formula_gap, baselineskip) | ||
| SPACING_MAP = { | ||
| "tiny": ("0pt", "0pt", "0pt", "0pt", "0pt"), | ||
| "small": ("2pt", "1pt", "1pt", "0.5pt", "2pt"), | ||
| "medium": ("8pt", "4pt", "4pt", "2pt", "8pt"), | ||
| "large": ("16pt", "8pt", "8pt", "4pt", "16pt"), | ||
| "tiny": ("0pt", "0pt", "0pt", "0pt", "0pt", "4pt"), | ||
| "small": ("2pt", "1pt", "1pt", "0.5pt", "2pt", "6pt"), | ||
| "medium": ("8pt", "4pt", "4pt", "2pt", "8pt", "10pt"), | ||
| "large": ("16pt", "8pt", "8pt", "4pt", "16pt", "14pt"), | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -47,7 +47,7 @@ def build_dynamic_header(columns=2, font_size="10pt", margins="0.25in", spacing= | |
| Build a dynamic LaTeX header based on user-selected options. | ||
| """ | ||
| size_command = FONT_SIZE_MAP.get(font_size, "\\footnotesize") | ||
| sec_before, sec_after, subsec_before, subsec_after, _ = SPACING_MAP.get(spacing, SPACING_MAP["large"]) | ||
| sec_before, sec_after, subsec_before, subsec_after, _, baseline_skip = SPACING_MAP.get(spacing, SPACING_MAP["large"]) | ||
|
|
||
| # The standard `article` class only supports 10pt/11pt/12pt. | ||
| # Use `extarticle` (from the extsizes package) for 8pt and 9pt. | ||
|
|
@@ -70,6 +70,7 @@ def build_dynamic_header(columns=2, font_size="10pt", margins="0.25in", spacing= | |
| "\\titleformat{\\subsection}{\\normalfont\\scriptsize\\bfseries}{}{0pt}{}", | ||
| 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, | ||
|
Comment on lines
+73
to
76
|
||
|
|
@@ -103,7 +104,7 @@ def build_latex_for_formulas(selected_formulas, columns=2, font_size="10pt", mar | |
| """ | ||
| header = build_dynamic_header(columns, font_size, margins, spacing) | ||
| footer = build_dynamic_footer(columns) | ||
| _, _, _, _, formula_gap = SPACING_MAP.get(spacing, SPACING_MAP["large"]) | ||
| _, _, _, _, formula_gap, _ = SPACING_MAP.get(spacing, SPACING_MAP["large"]) | ||
|
|
||
| if not selected_formulas: | ||
| return header + footer | ||
|
|
@@ -124,10 +125,10 @@ def build_latex_for_formulas(selected_formulas, columns=2, font_size="10pt", mar | |
| body_lines.append(r"\end{flushleft}") | ||
| in_flushleft = False | ||
| if current_class is not None: | ||
| body_lines.append("") | ||
| body_lines.append("%") # Suppress paragraph break between sections | ||
| escaped_class = class_name.replace("&", "\\&") | ||
| body_lines.append("\\section*{" + escaped_class + "}") | ||
| body_lines.append("") | ||
| body_lines.append("%") # Suppress paragraph break after section | ||
| current_class = class_name | ||
| current_category = None | ||
|
|
||
|
|
@@ -139,7 +140,7 @@ def build_latex_for_formulas(selected_formulas, columns=2, font_size="10pt", mar | |
| if not is_special: | ||
| escaped_category = category.replace("&", "\\&") | ||
| body_lines.append("\\subsection*{" + escaped_category + "}") | ||
| body_lines.append("") | ||
| body_lines.append("%") | ||
| body_lines.append(r"\begin{flushleft}") | ||
| in_flushleft = True | ||
| current_category = category | ||
|
|
@@ -149,9 +150,10 @@ def build_latex_for_formulas(selected_formulas, columns=2, font_size="10pt", mar | |
| else: | ||
| # Escape special LaTeX characters in the formula name | ||
| escaped_name = name.replace("\\", "\\textbackslash ").replace("&", "\\&").replace("%", "\\%").replace("#", "\\#").replace("_", "\\_").replace("^", "\\textasciicircum ").replace("{", "\\{").replace("}", "\\}") | ||
| body_lines.append("\\textbf{" + escaped_name + "}") | ||
| body_lines.append("\\[ \\adjustbox{max width=\\linewidth}{\\displaystyle " + latex + "} \\]") | ||
| body_lines.append(f"\\\\[{formula_gap}]") | ||
| body_lines.append(r"\textbf{" + escaped_name + "}") | ||
| body_lines.append(r"\[" + r" \adjustbox{max width=\linewidth}{$" + latex + r"$} " + r"\]") | ||
| if formula_gap != "0pt": | ||
| body_lines.append(r"\vspace{" + formula_gap + "}") | ||
|
|
||
| if in_flushleft: | ||
| body_lines.append(r"\end{flushleft}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,11 +131,69 @@ export function useLatex(initialData) { | |
| isCompilingRef.current = true; | ||
| setIsCompiling(true); | ||
| setCompileError(null); | ||
|
|
||
| let contentToCompile = content; | ||
|
|
||
| try { | ||
| const response = await fetch('/api/generate-sheet/', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ | ||
| formulas: [], | ||
| columns: columns, | ||
| font_size: fontSize, | ||
| spacing: spacing, | ||
| margins: margins | ||
| }), | ||
| }); | ||
| if (response.ok) { | ||
| const data = await response.json(); | ||
| const newLatex = data.tex_code; | ||
|
|
||
| const oldBodyMatch = content.match(/\\begin\{document\}([\s\S]*)\\end\{document\}/); | ||
|
|
||
| if (oldBodyMatch) { | ||
| const oldBody = oldBodyMatch[1]; | ||
|
|
||
| const multicolMatch = oldBody.match(/\\begin\{multicols\}\{(\d+)\}([\s\S]*?)\\end\{multicols\}/); | ||
|
|
||
| let formulaContent = oldBody; | ||
| if (multicolMatch) { | ||
| formulaContent = multicolMatch[2]; | ||
|
Comment on lines
+158
to
+162
|
||
| } | ||
|
|
||
| const newParts = newLatex.split('\\begin{multicols}'); | ||
| if (newParts.length > 1) { | ||
| const afterMulticols = newParts[1]; | ||
| const columnMatch = afterMulticols.match(/^\{(\d+)\}/); | ||
|
|
||
| if (columnMatch) { | ||
| const columnCount = columnMatch[1]; | ||
| const afterColumn = afterMulticols.slice(columnMatch[0].length); | ||
|
|
||
| const beforeEnd = afterColumn.split('\\end{multicols}')[0]; | ||
| const afterEnd = afterColumn.split('\\end{multicols}').slice(1).join('\\end{multicols}'); | ||
|
|
||
| contentToCompile = newParts[0] + '\\begin{multicols}{' + columnCount + '}' + beforeEnd + formulaContent + '\\end{multicols}' + afterEnd; | ||
| } else { | ||
| contentToCompile = newLatex; | ||
| } | ||
| } else { | ||
| contentToCompile = newLatex; | ||
| } | ||
| } else { | ||
| contentToCompile = newLatex; | ||
| } | ||
| } | ||
| } catch (e) { | ||
| console.log('Regenerate failed, using existing content:', e); | ||
| } | ||
|
|
||
| try { | ||
| const response = await fetch('/api/compile/', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ content }), | ||
| body: JSON.stringify({ content: contentToCompile }), | ||
| }); | ||
| if (!response.ok) { | ||
| const errorData = await response.json().catch(() => ({})); | ||
|
|
@@ -163,7 +221,7 @@ export function useLatex(initialData) { | |
| setIsCompiling(false); | ||
| isCompilingRef.current = false; | ||
| } | ||
| }, [content]); | ||
| }, [content, columns, fontSize, spacing, margins]); | ||
|
|
||
| const handlePreview = useCallback(async (latexContent = null, regenerateOptions = null) => { | ||
| if (isCompilingRef.current) return; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\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.