Skip to content

Passing a new parameter from index.Rmd to a .sty file in csasdown

Sean Anderson edited this page Dec 10, 2019 · 4 revisions

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.

  1. Open csasdown/inst/rmarkdown/templates/techreport/skeleton/skeleton.Rmd. Note that this file is what ultimately gets turned into an index.Rmd file when someone creates a new draft.

  2. 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: "".

  3. 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 $$.

  4. 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 becomes Cat. No. Fs97-6/\trReportNum{}E-PDF \quad ISBN \trISBN{} \quad ISSN 1488-5379.

  5. 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.

  1. Do the same thing to the French .tex and .sty files you edited above. Note that both languages share a common skeleton.Rmd file.

  2. Switch your working directory back to the main package directory if needed. Run the unit tests and/or package check. devtools::test() or devtools::check().

  3. If everything is OK, then commit your changes with Git and push your commit. Create a pull request if needed.