Skip to content

Refactor TEX and SVG temporary files to use stdin#1682

Open
a1-su wants to merge 1 commit intoCourseography:masterfrom
a1-su:refactor-temporary-files
Open

Refactor TEX and SVG temporary files to use stdin#1682
a1-su wants to merge 1 commit intoCourseography:masterfrom
a1-su:refactor-temporary-files

Conversation

@a1-su
Copy link
Contributor

@a1-su a1-su commented Mar 19, 2026

Proposed Changes

This PR refactors the returnPDF, exportTimetablePDFResponse, and graphImageResponse to use stdin instead of the temporary, intermediate .tex and .svg files it was using previously. Instead of creating the temporary files, the tex and svg contents are directly being piped into the pdflatex and magick processes.

Note that while returnPDF in Controllers/Timetable.hs now entirely uses stdin instead of tex temporary files, createImageFile in Export/ImageConversion.hs still uses temporary svg files and the new withImageFile function handles piping the svg contents instead, because the temporary svg is still required for renderTableHelper in Export/TimetableImageCreator.hs.

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality) X
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CircleCI checks have passed.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

  • There are some odd remnants of the old code that I can change depending on what is seen fit. Notably, in Export/PdfGenerator.hs, the createPDF function used two-space tabs instead of four, and has the "Waiting for a process..." and "Process Complete" logs which I can remove should it be unneeded.

@a1-su a1-su requested a review from david-yz-liu March 19, 2026 01:19
@coveralls
Copy link

Pull Request Test Coverage Report for Build bfc72401-527a-4903-9f9c-00af9c843ae6

Details

  • 0 of 11 (0.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.05%) to 56.478%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/Controllers/Graph.hs 0 4 0.0%
app/Export/ImageConversion.hs 0 7 0.0%
Totals Coverage Status
Change from base Build ac1c0723-45d7-45be-8bea-efc2c6525e84: -0.05%
Covered Lines: 2280
Relevant Lines: 3960

💛 - Coveralls

Copy link
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @a1-su, I just left a few comments. Modifying the indentation of createPDF is okay here, as you modifying the overall function content quite a bit.

(Just hin, _, _, pid) <- createProcess (proc "magick" ["svg:-", outName]) { std_in = CreatePipe }
writeAction hin
hClose hin
putStrLn "Waiting for process..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think you can delete these logging calls (throughout)

generateTex :: [String] -> String -> IO ()
generateTex imageNames texName = execLaTeXT (buildTex imageNames) >>= renderFile texName
-- | Generates a TEX text that includes all of the images in imageNames
generateTex :: [String] -> IO Text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this function is not writing to a file, I think we should be able to make it pure ([String] -> Text)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants