Skip to content

[herd][preview] Fix preview multiple files#1909

Merged
HadrienRenaud merged 4 commits into
herd:masterfrom
HadrienRenaud:fix-preview-multiple-files
Jul 14, 2026
Merged

[herd][preview] Fix preview multiple files#1909
HadrienRenaud merged 4 commits into
herd:masterfrom
HadrienRenaud:fix-preview-multiple-files

Conversation

@HadrienRenaud

@HadrienRenaud HadrienRenaud commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Also:

  • do not try to open the pdf viewer if the pdf generator failed
  • do not suppress error output from sub-commands when in -debug pretty

After implementing the changes suggested in review:

  • merge the generated files into a single PDF using a MacOS builtin app
  • remove temporary generated pdf file, so that only the pdf file opened by preview is kept

@HadrienRenaud HadrienRenaud requested a review from maranget July 9, 2026 13:32
@HadrienRenaud HadrienRenaud self-assigned this Jul 9, 2026

@relokin relokin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a very useful PR, thanks Hadrien. I've got one suggestion but feel free to merge this as-is.

Comment thread herd/show.ml Outdated
| Evince -> do_show_file name_dot "evince" "pdf"
| Preview ->
do_show_file ~keep_tmp_pdf:true name_dot "open -a Preview" "pdf"
run_cmd "%s -Tpdf %s -O && open -a Preview %s.*pdf" generator name_dot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth trying to combine the pdfs into one? Something along the lines of:

Suggested change
run_cmd "%s -Tpdf %s -O && open -a Preview %s.*pdf" generator name_dot
let join_app = "/System/Library/Automator/Combine\ PDF\ Pages.action/Contents/MacOS/join" in
run_cmd "%s -Tpdf %s -O" generator name_dot ;
run_cmd "%s -o %s %s.*.pdf" join_app name_dot name_dot ;
run_cmd "open -a Preview %s.pdf" name_dot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tried @relokin's nice idea with the following, slightly modified, code.

       let join_app =
         {| /System/Library/Automator/Combine\ PDF\ Pages.action/Contents/MacOS/join |} in
      run_cmd "%s -Tpdf %s -O && %s -o %s.all.pdf %s*.pdf && open -a Preview %s.all.pdf"
        generator name_dot
        join_app name_dot name_dot
        name_dot

I like having one window with all diagrams right from the start better then having several windows initially, even if one can regroup them with "Merge all windows" (Menu Window).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've implemented something similar in d1319fd. Please have a look and let me know what you think

@maranget maranget left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Consider our comments on merging the PDF files though.

@HadrienRenaud HadrienRenaud force-pushed the fix-preview-multiple-files branch from 056a1b4 to 87ebf0c Compare July 13, 2026 09:24
@HadrienRenaud

Copy link
Copy Markdown
Collaborator Author

Thank you @maranget and @relokin for the reviews. I've implemented the suggested changes, but because it's bash I'd like for a few tests on other machines before merging. Could you please re-try using it?

@maranget maranget left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worked for me and code looks fine.

The previous commits created a pdf file per execution shown, and the
previous commit merged them into a single PDF file. This commit cleans
up the files that are merged.

Notice that after this commit, there is no difference when showing a
single pdf file.
@HadrienRenaud HadrienRenaud force-pushed the fix-preview-multiple-files branch from 9cea122 to 8a83b1c Compare July 14, 2026 06:16
@HadrienRenaud HadrienRenaud merged commit d79c2d6 into herd:master Jul 14, 2026
3 checks passed
@HadrienRenaud HadrienRenaud deleted the fix-preview-multiple-files branch July 14, 2026 06:28
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