Skip to content

Instantly share code, notes, and snippets.

@mhucka
Last active March 29, 2022 20:34
Show Gist options
  • Save mhucka/5ecb18aa2fd088c055de07366f70135e to your computer and use it in GitHub Desktop.
Save mhucka/5ecb18aa2fd088c055de07366f70135e to your computer and use it in GitHub Desktop.
Makefile for generating a preview of a JOSS journal paper
# =============================================================================
# @file Makefile
# @brief Makefile for generating previews of the paper
# @author Michael Hucka <mhucka@caltech.edu>
# @license Please see the file named LICENSE in the project directory
# @website https://github.com/casics/dassie
# =============================================================================
# Change the following values to match your configuration.
# .............................................................................
input := paper.md
output := paper.pdf
bib := paper.bib
# Main code -- no more customization variables after this point
# .............................................................................
title := $(shell grep title: $(input) | sed 's/title: *//' | tr -d "'")
authors := $(shell sed -n '/authors:/,/affiliations:/p' $(input) | grep name: | sed 's/- name: *//' | paste -d, -s - | sed 's/,/, /g')
repo := $(shell git remote get-url origin | sed 's|git@github.com:|https://github.com/|' | sed 's/\.git//')
$(output): $(input) $(bib) Makefile
pandoc \
-V paper_title="$(title)" \
-V citation_author="$(authors)" \
-V repository="$(repo)" \
-V archive_doi="http://dx.doi.org/00.00000/zenodo.0000000" \
-V formatted_doi="00.00000/joss.00000" \
-V paper_url="http://joss.theoj.org/papers/" \
-V review_issue_url="http://joss.theoj.org/papers/" \
-V issue="0" \
-V volume="00" \
-V year="2018" \
-V submitted="00 January 0000" \
-V published="00 January 0000" \
-V page="00" \
-V graphics="true" \
-V joss_logo_path="whedon/resources/joss-logo.png" \
-V geometry:margin=1in \
-o $(output) \
--pdf-engine=xelatex \
--filter pandoc-citeproc $(input) \
--from markdown+autolink_bare_uris \
--template "whedon/resources/latex.template"
autorefresh:;
((ls $(input) $(bib) | entr make $(output)) &)
@mhucka
Copy link
Author

mhucka commented Feb 9, 2018

While writing and submitting a new JOSS paper, I updated the Makefile to grab the title and authors automatically from the .md file. The updated version is shown above.

@mhucka
Copy link
Author

mhucka commented Feb 13, 2018

I forgot to mention: for this to work, one needs to clone the whedon repo into the current directory. (It wouldn't be hard to put that location in a variable in the makefile, or even have the makefile do a git clone if it can't find a copy of whedon...)

@steven-murray
Copy link

Thanks for this! I found it very useful. In my case, I wanted to post my paper on arXiv, which will not accept pdf submissions (you have to submit the latex source). I did have to modify a few things from this Makefile, as seen below:

# =============================================================================
# @file    Makefile
# @brief   Makefile for generating previews of the paper
# @author  Michael Hucka <mhucka@caltech.edu>
# @license Please see the file named LICENSE in the project directory
# @website https://github.com/casics/dassie
# =============================================================================

# Change the following values to match your configuration.
# .............................................................................

input   := paper

vol     := 0
issue   := 00
gh_issue  := 000
year    := 2018
submitted := 23 July $(year)
accepted  := 21 August $(year)

# Main code -- no more customization variables after this point
# .............................................................................

title   := $(shell grep title: $(input).md | sed 's/title: *//' | tr -d "'")
authors := $(shell sed -n '/authors:/,/affiliations:/p' $(input).d | grep name: | sed 's/- name: *//' | paste -d, -s - | sed 's/,/, /g')
repo    := $(shell git remote get-url origin | sed 's|git@github.com:|https://github.com/|' | sed 's/\.git//')

$(input).tex: $(input).md $(input).bib Makefile
        /usr/bin/pandoc \
        -V paper_title="$(title)" \
        -V footnote_paper_title="$(title)" \
        -V citation_author="$(authors)" \
        -V repository="$(repo)" \
        -V archive_doi="http://dx.doi.org/10.21105/zenodo.1400822" \
        -V formatted_doi="10.21105/joss.00850" \
        -V paper_url="http://joss.theoj.org/papers/" \
        -V review_issue_url="https://github.com/openjournals/joss-reviews/issues/$(issue)" \
        -V issue="$(issue)" \
        -V volume="$(vol)" \
        -V year="$(year)" \
        -V submitted="$(submitted)" \
        -V published="$(accepted)" \
        -V page="$(issue)" \
        -V graphics="true" \
        -V logo_path="joss-logo.png" \
        -V geometry:margin=1in \
        --verbose \
        -o $(input).tex \
        --pdf-engine=xelatex \
        --filter /usr/bin/pandoc-citeproc $(input).md \
        --from markdown+autolink_bare_uris \
        --template "latex.template"

$(input).pdf: $(input).tex
        xelatex $(input).tex

autorefresh:;
        ((ls $(input).md $(input).bib | entr make $(input).tex) &)

Note that I copied the whedon/resources/latex.template and whedon/resources/joss-logo.png into the same directory as the paper.md (this enabled me to zip it all up for submission). I also needed to comment out the line in the latex.template that set the bibliography (not quite sure why). It should be easy enough to auto-download those two files to the current directory in the Makefile, but I couldn't be bothered. Also, this keeps the actual tex file.

@rheiland
Copy link

Note that this apparently requires pandoc > 2.0. And beware that your Anaconda installation may be providing < 2.0 (as I just discovered).

@pmundt
Copy link

pmundt commented Jun 16, 2021

There have a few changes in the whedon repository since this was written. The logo path and variable must now be changed to:

        -V logo_path="whedon/resources/joss/logo.png" \

or you will end up with a not very helpful error:

Error producing PDF.
! LaTeX Error: File `' not found.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.315 \end{document}

make: *** [Makefile:24: paper.pdf] Error 43

This is due to an update in the latex.template that now looks for logo_path. The logo has also been shifted and now lives in whedon/resources/joss/logo.png.

@mhucka
Copy link
Author

mhucka commented Jun 18, 2021

@pmundt thank you very much for that information. I am about to start writing another JOSS paper and will have a chance to test it and update this gist.

@mhucka
Copy link
Author

mhucka commented Jun 18, 2021

@steven-murray thank you very much for your work as well!
@rheiland thanks for your note. You made me realize this makefile should check the versions of things too.

@pmundt
Copy link

pmundt commented Jun 24, 2021

@mhucka Note that the current version (with the aforementioned fixes applied) is unable to generate citations properly, I'm not sure if this was always a limitation or just something that's been broken by updates in the whedon latex template. I'll see if I can figure out what's going wrong, but have limited time to hunt this down at the moment.

@mhucka
Copy link
Author

mhucka commented Mar 28, 2022

Update for anyone who comes across this: I put a newer version of this Makefile in a separate gist at https://gist.github.com/mhucka/c0b82778417f38f7ae6ee7d051cec90a The new version incorporates changes from @steven-murray above and hopefully fixes a few issues like the one noted by @pmundt.

Update 2022-03-29: Discovered JOSS has changed to a different scheme for generating papers, and no longer uses Whedon. The updated makefile in the new gist doesn't account for that. I'm deleting the gist to avoid confusion.

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