-
Notifications
You must be signed in to change notification settings - Fork 17
Passing a new parameter from index.Rmd to a .sty file in csasdown
This is a quick set of notes for how to add a new parameter that needs to be passed from the main index.Rmd file through the .tex and into the .sty file. For example, to fix this issue.
These instructions will correspond to Technical Reports, but the same instructions apply to Science Responses or Research Documents (replacing techreport
or tech-report
with res-doc
or sr
).
Note that you need to do this in the R package and reload the package for your changes to take effect. Every time a document is built, the package .sty file overwrites your local .sty file. Therefore, edit the package and make a pull request so that others can benefit from your changes.
-
Open
csasdown/inst/rmarkdown/templates/techreport/skeleton/skeleton.Rmd
. Note that this file is what ultimately gets turned into anindex.Rmd
file when someone creates a new draft. -
Name your new parameter/argument something short and useful. Use lowercase and underscores if necessary. Add a default value. In this case, I added
isbn: ""
. -
Open
csasdown/inst/csas-tex/tech-report.tex
. Create a new TeX command that grabs the YAML argument. Name it something reasonable following the format you see for other parameters. In this case,\newcommand{\trISBN}{$isbn$}
. Note that in order to refer to your .Rmd YAML parameter, you need to surround it in$$
. -
Open
csasdown/inst/csas-style/tech-report.sty
. Add the TeX command where you want it to appear. In this case,Cat. No. Fs97-6/\trReportNum{}E-PDF \quad ISSN 1488-5379
becomesCat. No. Fs97-6/\trReportNum{}E-PDF \quad ISBN \trISBN{} \quad ISSN 1488-5379
. -
Test that it works:
devtools::install(quick = TRUE, dependencies = FALSE) # install the package
setwd("~/Desktop/") # or wherever
csasdown::draft("techreport", create_dir = TRUE)
Open index.Rmd, knit it, check the output. Iterate on the above if necessary.
-
Do the same thing to the French .tex and .sty files you edited above. Note that both languages share a common
skeleton.Rmd
file. -
Switch your working directory back to the main package directory if needed. Run the unit tests and/or package check.
devtools::test()
ordevtools::check()
. -
If everything is OK, then commit your changes with Git and push your commit. Create a pull request if needed.