Skip to content
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

update sn template to 12/2023 and support csl or natbib #2

Merged
merged 34 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d4060b9
chore: update bibliography styles
cameronraysmith Mar 3, 2024
b7dbe19
chore(sn-jnl): update documentclass
cameronraysmith Mar 3, 2024
f846689
chore(extension): update format-resources
cameronraysmith Mar 3, 2024
cddf2e7
nit: make default `cite-method` explicit
cameronraysmith Mar 3, 2024
c9b2206
docs: note caveats of natbib styles
cameronraysmith Mar 3, 2024
a0e5887
chore: update example build output
cameronraysmith Mar 3, 2024
04b0644
docs: update README
cameronraysmith Mar 3, 2024
30d9b0f
fix(doc-class): include comma after journal
cameronraysmith Mar 4, 2024
22281b4
feat(template): illustrate use of classoption
cameronraysmith Mar 4, 2024
8214cbd
chore: update example build output
cameronraysmith Mar 4, 2024
066ed3d
docs: nit `classoption`
cameronraysmith Mar 4, 2024
d37cb16
docs: nit remove reference to removed bib style
cameronraysmith Mar 4, 2024
43ae1f4
feat: add Makefile
cameronraysmith Mar 4, 2024
b21c2e1
fix: update gitignore
cameronraysmith Mar 4, 2024
8bb0150
feat: vendor a set of csl files
cameronraysmith Mar 4, 2024
ff74ecd
feat(template): use vendored csl to mirror natbib styles
cameronraysmith Mar 4, 2024
8657c43
chore: update example build output
cameronraysmith Mar 4, 2024
08012d0
docs: update README
cameronraysmith Mar 4, 2024
45a38f9
chore: update make help
cameronraysmith Mar 4, 2024
d03a9df
chore(make): add clean targets
cameronraysmith Mar 4, 2024
16461eb
fix(doc-class): rename journal to natbibstyle
cameronraysmith Mar 4, 2024
2427327
fix(template): rename journal to natbibstyle
cameronraysmith Mar 4, 2024
661642d
chore: update example build output
cameronraysmith Mar 4, 2024
14e1ca7
nit: remove unnecessary rm force
cameronraysmith Mar 4, 2024
1aa8fb7
feat(make): add target to extract pdf image preview
cameronraysmith Mar 4, 2024
9580ab1
chore: update image preview
cameronraysmith Mar 4, 2024
b94de9a
chore: update readme
cameronraysmith Mar 4, 2024
ea663d0
fix(template): add comments to clarify citeproc versus natbib logic
cameronraysmith Mar 4, 2024
442bec4
chore(quartoignore): add Makefile
cameronraysmith Mar 26, 2024
4a4e19f
docs(readme): note CSL `CC BY-SA 3.0`
cameronraysmith Mar 26, 2024
38b4098
fix(template): use `journal.cite-style` instead of `natbibstyle`
cameronraysmith Apr 23, 2024
6e68534
chore: render
cameronraysmith Apr 23, 2024
f1a05ac
chore(_extension): update authors
cameronraysmith Apr 23, 2024
d18b5ea
chore(gitattributes): mark vendored template and csl styles
cameronraysmith Apr 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_extensions/nature/csl/* linguist-vendored
_extensions/nature/*.bst linguist-vendored
_extensions/nature/sn-jnl.cls linguist-vendored
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
.Rdata
.httr-oauth
.DS_Store
/template_files/
*.aux
*.fdb_latexmk
*.fls
*.log
/*.bst
/*.cls
template.*
!template.{qmd,pdf}
3 changes: 2 additions & 1 deletion .quartoignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pdf
*.png
*.rproj
*.Rproj
*.Rproj
Makefile
90 changes: 90 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
.DEFAULT_GOAL := help

ENV_PREFIX ?= .
ENV_FILE := $(wildcard $(ENV_PREFIX)/.env)

ifeq ($(strip $(ENV_FILE)),)
$(info $(ENV_PREFIX)/.env file not found, skipping inclusion)
else
include $(ENV_PREFIX)/.env
export
endif

GIT_SHA_SHORT = $(shell git rev-parse --short HEAD)
GIT_REF = $(shell git rev-parse --abbrev-ref HEAD)

#-------
##@ help
#-------

# based on "https://gist.github.com/prwhite/8168133?permalink_comment_id=4260260#gistcomment-4260260"
help: ## Display this help. (Default)
@grep -hE '^(##@|[A-Za-z0-9_ \-]*?:.*##).*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; /^##@/ {print "\n" substr($$0, 5)} /^[A-Za-z0-9_ \-]*?:.*##/ {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

help-sort: ## Display alphabetized version of help (no section headings).
@grep -hE '^[A-Za-z0-9_ \-]*?:.*##.*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; /^[A-Za-z0-9_ \-]*?:.*##/ {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

HELP_TARGETS_PATTERN ?= test
help-targets: ## Print commands for all targets matching a given pattern. eval "$(make help-targets HELP_TARGETS_PATTERN=render | sed 's/\x1b\[[0-9;]*m//g')"
@make help-sort | awk '{print $$1}' | grep '$(HELP_TARGETS_PATTERN)' | xargs -I {} printf "printf '___\n\n{}:\n\n'\nmake -n {}\nprintf '\n'\n"



#--------------------------
##@ download csl bibliography style files
#--------------------------

# list of citation style names to vendor
CITATION_STYLES = \
nature-no-superscript \
springer-basic-author-date \
springer-basic-brackets-no-et-al \
springer-humanities-author-date \
springer-humanities-brackets \
springer-mathphys-author-date \
springer-mathphys-brackets \
springer-vancouver

# base URL for downloading the citation styles
BASE_URL = https://www.zotero.org/styles/

CSL_PREFIX ?= _extensions/nature/csl

download-csl-files: ## Download citation style files. Pass FORCE=1 to download even if file exists.
mkdir -p $(CSL_PREFIX)
@$(foreach style,$(CITATION_STYLES),\
if [ "$(FORCE)" = "1" ] || [ ! -f "$(CSL_PREFIX)/$(style).csl" ]; then \
echo "downloading: $(style).csl"; \
wget -O $(CSL_PREFIX)/$(style).csl $(BASE_URL)$(style); \
else \
echo "$(style).csl exists. skipping..."; \
fi;)

#-----------------
##@ render article
#-----------------

DOCUMENT_NAME ?= template

render-latex: ## Render the article via LaTeX
quarto render $(DOCUMENT_NAME).qmd --to nature-pdf

render: ## Render all article formats including pdf, html, and docx
quarto render $(DOCUMENT_NAME).qmd --to all

clean: ## Clean compilation artifacts
rm sn-*.{bst,cls} || true

clean-all: ## Clean all files including output files
clean-all: clean
rm $(DOCUMENT_NAME).{tex,pdf,html,docx} || true
rm -r $(DOCUMENT_NAME)_files/

#-------
##@ regenerate preview
#-------

extract-preview: ## Extract the first page of the pdf as a png for the preview
pdftoppm -f 1 -l 1 -png $(DOCUMENT_NAME).pdf > $(DOCUMENT_NAME)_1.png
62 changes: 53 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,77 @@ Then, add the format to your document options:
```yaml
format:
nature-pdf: default
```
```

## Options

- `journal`: the Nature subjournal
- `journal.cite-style`: the name of the natbib style for the Nature subjournal
- `default`: Default
- `sn-nature`: Style for submissions to Nature Portfolio journals
- `sn-basic`: Basic Springer Nature Reference Style/Chemistry Reference Style
- `sn-mathphys`: Math and Physical Sciences Reference Style
- `sn-mathphys-ay`: Math and Physical Sciences Reference Style (author-year)
- `sn-mathphys-num`: Math and Physical Sciences Reference Style (numbered)
- `sn-aps`: American Physical Society (APS) Reference Style
- `sn-vancouver`: Vancouver Reference Style
- `sn-apa`: APA Reference Style
- `sn-chicago`: Chicago-based Humanities Reference Style
- `classoptions`:
- `iicol`: double column layout, usually used with `journal: default`
- `Numbered`: Numbered reference style, usually used with `journal: sn-mathphys` or `journal: sn-vancouver`.
- `classoption`:
- `iicol`: double column layout, usually used with `journal.cite-style: default`
- `Numbered`: Numbered reference style, usually used with `journal.cite-style: sn-vancouver`.
- `referee`: double spaced for first submissions
- `lineno`: print line numbers in the margin

Since `cite-method: citeproc` is the
[default](https://quarto.org/docs/authoring/footnotes-and-citations.html#sec-biblatex),
to respect the natbib reference styles, you would need to set `cite-method: natbib`,
such as:

```yaml
format:
nature-pdf:
journal:
cite-style: sn-mathphys-num
cite-method: natbib
```

and restrict usage to [pandoc standard](https://pandoc.org/MANUAL.html#citation-syntax)
references: `[@key01; @key02]`. This has the advantage that it will respect the styles
officially included in the [Springer Nature template][springer-template].
However it has the disadvantage that the citations will not be consistent with
html and docx outputs. To achieve this, set

```yaml
cameronraysmith marked this conversation as resolved.
Show resolved Hide resolved
csl: ./path/to/springer-basic-author-date.csl
```

to a path to a CSL file. Several are vendered in
[_extensions/nature/csl/](./_extensions/nature/csl/).
Additional CSL style files can be found in the
[citation-style-language/styles](https://github.com/citation-style-language/styles)
repository, the [recommended](https://citationstyles.org/authors/)
[Zotero Style Repository](https://www.zotero.org/styles) for downloading these
styles, and elsewhere[^1]. The `csl` parameter can be specified independent of the
specification of `cite-method: citeproc` or `cite-method: natbib` but the former
will lead to consistency of the pdf output with html and docx while the latter
will use the csl file with citeproc for non-LaTeX outputs and natbib for the
LaTeX-rendered pdf.

[^1]: The vendored Citation Style Language (CSL) files are copyrighted by the [Citation Style Language project](https://citationstyles.org/). These files have not been modified and are redistributed as licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License ([CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)).

## Example

Here is the source code for a minimal sample document: [template.qmd](template.qmd).

<!-- pdftools::pdf_convert('template.pdf',pages = 1) -->
![[template.qmd](template.qmd)](template_1.png)
<div style="width: 100%; text-align: left;">
<a href="template.pdf">
<img src="template_1.png" width="500" alt="link to template.pdf" style="max-width:100%;height:auto;">
</a>
</div>

## License

This modifies the Springer Nature journal article template package, available at <https://www.springernature.com/gp/authors/campaigns/latex-author-support/see-where-our-services-will-take-you/18782940>.
The original template is licensed under the [LaTeX Project Public License 1.3c](https://www.latex-project.org/lppl/lppl-1-3c/). The template within is derived from this and makes modifications to separate into the full document into Quarto "partials". All modifications can be seen in this repo.
This modifies the [Springer Nature journal article template package][springer-template].
cameronraysmith marked this conversation as resolved.
Show resolved Hide resolved
The original template is licensed under the [LaTeX Project Public License 1.3c](https://www.latex-project.org/lppl/lppl-1-3c/). The template within is derived from this and makes modifications to separate into the full document into Quarto "partials". All modifications can be seen in this repo.

[springer-template]: https://www.springernature.com/gp/authors/campaigns/latex-author-support/see-where-our-services-will-take-you/18782940
6 changes: 3 additions & 3 deletions _extensions/nature/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
title: Nature Journal Template
author: Christopher Kenny
author: Christopher Kenny, Cameron Smith
version: 1.0.0
quarto-required: ">=1.4.0"
contributes:
Expand All @@ -14,7 +14,8 @@ contributes:
- sn-aps.bst
- sn-basic.bst
- sn-chicago.bst
- sn-mathphys.bst
- sn-mathphys-ay.bst
- sn-mathphys-num.bst
- sn-nature.bst
- sn-vancouver.bst
template-partials:
Expand All @@ -23,4 +24,3 @@ contributes:
- "partials/_author.tex"
- "partials/_affiliation.tex"
- "partials/before-body.tex"

127 changes: 127 additions & 0 deletions _extensions/nature/csl/nature-no-superscript.csl
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="sort-only" default-locale="en-GB">
<info>
<title>Nature (no superscript)</title>
<id>http://www.zotero.org/styles/nature-no-superscript</id>
<link href="http://www.zotero.org/styles/nature-no-superscript" rel="self"/>
<link href="http://www.nature.com/clpt/clptguidetoauthors.pdf" rel="documentation"/>
<author>
<name>Michael Berkowitz</name>
<email>[email protected]</email>
</author>
<category citation-format="numeric"/>
<category field="science"/>
<category field="generic-base"/>
<updated>2022-07-02T13:18:26+00:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<macro name="title">
<choose>
<if type="bill book graphic legal_case legislation motion_picture report song" match="any">
<text variable="title" font-style="italic"/>
</if>
<else-if type="chapter" match="any"/>
<else>
<text variable="title"/>
</else>
</choose>
</macro>
<macro name="author">
<names variable="author">
<name sort-separator=", " delimiter=", " and="symbol" initialize-with=". " delimiter-precedes-last="never" name-as-sort-order="all"/>
<label form="short" prefix=", "/>
<et-al font-style="italic"/>
</names>
</macro>
<macro name="access">
<choose>
<if variable="volume" type="article" match="any"/>
<else-if variable="DOI">
<text variable="DOI" prefix="doi:"/>
</else-if>
<else-if variable="URL">
<text term="at"/>
<text variable="URL" prefix=" &lt;" suffix="&gt;"/>
</else-if>
</choose>
</macro>
<macro name="issuance">
<choose>
<if type="bill book graphic legal_case legislation motion_picture report song chapter paper-conference" match="any">
<group delimiter=", " prefix="(" suffix=").">
<text variable="publisher" form="long"/>
<date variable="issued">
<date-part name="year"/>
</date>
</group>
</if>
<else-if type="article">
<group delimiter=" ">
<choose>
<if variable="genre" match="any">
<text variable="genre" text-case="capitalize-first"/>
</if>
<else>
<text term="article" text-case="capitalize-first"/>
</else>
</choose>
<text term="at"/>
<choose>
<if variable="DOI" match="any">
<text variable="DOI" prefix="https://doi.org/"/>
</if>
<else>
<text variable="URL"/>
</else>
</choose>
<date date-parts="year" form="text" variable="issued" prefix="(" suffix=")"/>
</group>
</else-if>
<else>
<date prefix="(" suffix=")." variable="issued">
<date-part name="year"/>
</date>
</else>
</choose>
</macro>
<macro name="editor">
<choose>
<if type="chapter paper-conference" match="any">
<names variable="editor" prefix="(" suffix=")">
<label form="short" suffix=" "/>
<name and="symbol" delimiter-precedes-last="never" initialize-with=". " name-as-sort-order="all"/>
</names>
</if>
</choose>
</macro>
<citation collapse="citation-number">
<sort>
<key variable="citation-number"/>
</sort>
<layout prefix="(" suffix=")" delimiter=",">
<text variable="citation-number"/>
</layout>
</citation>
<bibliography et-al-min="6" et-al-use-first="1" second-field-align="flush" entry-spacing="0" line-spacing="2">
<layout>
<text variable="citation-number" suffix="."/>
<group delimiter=" ">
<text macro="author" suffix="."/>
<text macro="title" suffix="."/>
<choose>
<if type="chapter paper-conference" match="any">
<text term="in" form="long" plural="false"/>
</if>
</choose>
<text variable="container-title" font-style="italic" form="short"/>
<text macro="editor"/>
<group font-weight="bold">
<text variable="volume" suffix=","/>
</group>
<text variable="page"/>
<text macro="issuance"/>
<text macro="access"/>
</group>
</layout>
</bibliography>
</style>
Loading