diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 150f740b3..4464460b0 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,10 +32,11 @@ jobs: matrix: config: # testing R release with last shipped pandoc version in RStudio IDE and new pandoc - - {os: windows-latest, pandoc: '3.1.9', r: 'release'} - - {os: macOS-latest, pandoc: '3.1.9', r: 'release'} + - {os: windows-latest, pandoc: '3.5', r: 'release'} + - {os: macOS-latest, pandoc: '3.5', r: 'release'} - {os: ubuntu-latest, pandoc: 'devel', r: 'release'} # testing older pandoc versions + - {os: ubuntu-latest, pandoc: '3.2.1', r: 'release'} # special \pandocbounded change - {os: ubuntu-latest, pandoc: '3.1.7', r: 'release'} # special citeproc change - {os: ubuntu-latest, pandoc: '2.19.2', r: 'release'} - {os: ubuntu-latest, pandoc: '2.18', r: 'release'} diff --git a/DESCRIPTION b/DESCRIPTION index 44bb14857..9df35e4e5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: rticles Title: Article Formats for R Markdown -Version: 0.27.3 +Version: 0.27.4 Authors@R: c( person("JJ", "Allaire", , "jj@posit.co", role = "aut"), person("Yihui", "Xie", , "xie@yihui.name", role = "aut", diff --git a/NEWS.md b/NEWS.md index f3c9b6c9e..3372614f3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,10 @@ # rticles (development version) - Fix `springer_article()` skeleton: It now uses `equal_contribution` in author field (thanks, @nielsbock, #568). -- Updaye `springer_aticle()` template to version 3 (December 2023): +- Update `springer_aticle()` template to version 3 (December 2023): - BREAKING CHANGE: sn-mathphys.bst has been split into Numbered and Author year style namely `sn-mathphys-num.bst` and `sn-mathphys-ay.bst` respectively. Skeleton has been updated. If you have existing article, you need to use `sn-mathphys-num` or `sn-mathphys-ay` option now, instead of `sn-mathphys`. +- Update all templates to work with Pandoc 3.2.1 by adding the definition of new `\pandocbounded` command used by Pandoc's LaTeX writers (see more at https://github.com/jgm/pandoc/releases/tag/3.2.1 and https://github.com/jgm/pandoc/issues/9660) (#571, #576). # rticles 0.27 diff --git a/R/utils.R b/R/utils.R index 119f00453..bf4686108 100644 --- a/R/utils.R +++ b/R/utils.R @@ -228,7 +228,8 @@ pdf_document_format <- function(format, args <- list_to_pandoc_variable_args(list( pandoc3 = rmarkdown::pandoc_available("3"), pandoc317 = rmarkdown::pandoc_available("3.1.7"), # new citeproc command - pandoc318 = rmarkdown::pandoc_available("3.1.8") # revised citeproc command + pandoc318 = rmarkdown::pandoc_available("3.1.8"), # revised citeproc command + pandoc321 = rmarkdown::pandoc_available("3.2.1") # new pandocbounded comment required )) fmt$pandoc$args <- c(fmt$pandoc$args, args) fmt diff --git a/inst/rmarkdown/templates/acm/resources/template.tex b/inst/rmarkdown/templates/acm/resources/template.tex index 48eb2f006..68699492e 100644 --- a/inst/rmarkdown/templates/acm/resources/template.tex +++ b/inst/rmarkdown/templates/acm/resources/template.tex @@ -17,24 +17,31 @@ % Add imagehandling $if(graphics)$ \usepackage{graphicx} -% Redefine \includegraphics so that, unless explicit options are -% given, the image width will not exceed the width of the page. -% Images get their normal width if they fit onto the page, but -% are scaled down if they would overflow the margins. +$if(pandoc321)$ +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +% Custom command from Pandoc 3.2.1 to scale images if necessary \makeatletter -\def\ScaleIfNeeded{% - \ifdim\Gin@nat@width>\linewidth - \linewidth - \else - \Gin@nat@width - \fi +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% } \makeatother -\let\Oldincludegraphics\includegraphics -{% - \catcode`\@=11\relax% - \gdef\includegraphics{\@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}}% -}% +$else$ +\makeatletter +\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} +\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} +\makeatother +% Scale images if necessary, so that they will not overflow the page +% margins by default, and it is still possible to overwrite the defaults +% using explicit options in \includegraphics[width, height, ...]{} +\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} +$endif$ $endif$ $if(svg)$ \usepackage{svg} diff --git a/inst/rmarkdown/templates/acs/resources/template.tex b/inst/rmarkdown/templates/acs/resources/template.tex index 14ee5c188..57e805d92 100644 --- a/inst/rmarkdown/templates/acs/resources/template.tex +++ b/inst/rmarkdown/templates/acs/resources/template.tex @@ -95,6 +95,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/aea/resources/template.tex b/inst/rmarkdown/templates/aea/resources/template.tex index ae4b4bdf9..0c5b99329 100644 --- a/inst/rmarkdown/templates/aea/resources/template.tex +++ b/inst/rmarkdown/templates/aea/resources/template.tex @@ -49,6 +49,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/agu/resources/template.tex b/inst/rmarkdown/templates/agu/resources/template.tex index f4034ca04..aa262c4d0 100644 --- a/inst/rmarkdown/templates/agu/resources/template.tex +++ b/inst/rmarkdown/templates/agu/resources/template.tex @@ -90,6 +90,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/amq/resources/template.tex b/inst/rmarkdown/templates/amq/resources/template.tex index a1df8622e..595d7851b 100644 --- a/inst/rmarkdown/templates/amq/resources/template.tex +++ b/inst/rmarkdown/templates/amq/resources/template.tex @@ -264,6 +264,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/ams/resources/template.tex b/inst/rmarkdown/templates/ams/resources/template.tex index 7d3b97afb..fbecc58ba 100644 --- a/inst/rmarkdown/templates/ams/resources/template.tex +++ b/inst/rmarkdown/templates/ams/resources/template.tex @@ -90,6 +90,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/arxiv/resources/template.tex b/inst/rmarkdown/templates/arxiv/resources/template.tex index 1e76dc025..f79e2089e 100644 --- a/inst/rmarkdown/templates/arxiv/resources/template.tex +++ b/inst/rmarkdown/templates/arxiv/resources/template.tex @@ -57,6 +57,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/asa/resources/template.tex b/inst/rmarkdown/templates/asa/resources/template.tex index 87557401d..7052025ee 100644 --- a/inst/rmarkdown/templates/asa/resources/template.tex +++ b/inst/rmarkdown/templates/asa/resources/template.tex @@ -56,6 +56,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/bioinformatics/resources/template.tex b/inst/rmarkdown/templates/bioinformatics/resources/template.tex index c69285bda..f55d11684 100644 --- a/inst/rmarkdown/templates/bioinformatics/resources/template.tex +++ b/inst/rmarkdown/templates/bioinformatics/resources/template.tex @@ -28,6 +28,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/biometrics/resources/template.tex b/inst/rmarkdown/templates/biometrics/resources/template.tex index 1d4517123..631b03ed7 100644 --- a/inst/rmarkdown/templates/biometrics/resources/template.tex +++ b/inst/rmarkdown/templates/biometrics/resources/template.tex @@ -63,6 +63,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/copernicus/resources/template.tex b/inst/rmarkdown/templates/copernicus/resources/template.tex index c6853fae0..4b62cc014 100644 --- a/inst/rmarkdown/templates/copernicus/resources/template.tex +++ b/inst/rmarkdown/templates/copernicus/resources/template.tex @@ -63,6 +63,25 @@ % Web Ecology (we) % Wind Energy Science (wes) +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + % Pandoc citation processing $if(csl-refs)$ % Pandoc citation processing diff --git a/inst/rmarkdown/templates/elsevier/resources/template.tex b/inst/rmarkdown/templates/elsevier/resources/template.tex index a77568c95..ab6e0028e 100644 --- a/inst/rmarkdown/templates/elsevier/resources/template.tex +++ b/inst/rmarkdown/templates/elsevier/resources/template.tex @@ -69,9 +69,23 @@ % For Pandoc feature verbatim_in_note \usepackage{fancyvrb} $endif$ -$if(graphics)$ -\usepackage{graphicx} -$endif$ +% Add imagehandling +$if(graphics)$$if(pandoc321)$ +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ $if(svg)$ \usepackage{svg} $endif$ diff --git a/inst/rmarkdown/templates/frontiers/resources/template.tex b/inst/rmarkdown/templates/frontiers/resources/template.tex index ca964188e..0c931d7e0 100644 --- a/inst/rmarkdown/templates/frontiers/resources/template.tex +++ b/inst/rmarkdown/templates/frontiers/resources/template.tex @@ -89,6 +89,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/glossa/resources/template.tex b/inst/rmarkdown/templates/glossa/resources/template.tex index 1ed1dc3f9..7145f6cf1 100644 --- a/inst/rmarkdown/templates/glossa/resources/template.tex +++ b/inst/rmarkdown/templates/glossa/resources/template.tex @@ -93,6 +93,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/ieee/resources/template.tex b/inst/rmarkdown/templates/ieee/resources/template.tex index c61da376d..15d437329 100644 --- a/inst/rmarkdown/templates/ieee/resources/template.tex +++ b/inst/rmarkdown/templates/ieee/resources/template.tex @@ -395,6 +395,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/ims/resources/template.tex b/inst/rmarkdown/templates/ims/resources/template.tex index b98434239..cd4332cef 100644 --- a/inst/rmarkdown/templates/ims/resources/template.tex +++ b/inst/rmarkdown/templates/ims/resources/template.tex @@ -154,7 +154,23 @@ % Garantees bookdown compilation %\usepackage{lmodern} - +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$ +$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +$else$ \makeatletter \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} @@ -163,10 +179,12 @@ % margins by default, and it is still possible to overwrite the defaults % using explicit options in \includegraphics[width, height, ...]{} \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} -% Set default figure placement to htbp \makeatletter +$endif$ +% Set default figure placement to htbp \def\fps@figure{htbp} \makeatother +$endif$ \setlength{\emergencystretch}{3em} % prevent overfull lines % alternative version to the shaded problem diff --git a/inst/rmarkdown/templates/informs/resources/template.tex b/inst/rmarkdown/templates/informs/resources/template.tex index 018b28eba..1ea17b552 100644 --- a/inst/rmarkdown/templates/informs/resources/template.tex +++ b/inst/rmarkdown/templates/informs/resources/template.tex @@ -39,6 +39,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/iop/resources/template.tex b/inst/rmarkdown/templates/iop/resources/template.tex index 3ba5b5841..94be6573d 100644 --- a/inst/rmarkdown/templates/iop/resources/template.tex +++ b/inst/rmarkdown/templates/iop/resources/template.tex @@ -51,6 +51,24 @@ \usepackage{etoolbox} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/isba/resources/template.tex b/inst/rmarkdown/templates/isba/resources/template.tex index c2f3a3fd2..cfd013993 100644 --- a/inst/rmarkdown/templates/isba/resources/template.tex +++ b/inst/rmarkdown/templates/isba/resources/template.tex @@ -49,6 +49,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/jasa/resources/template.tex b/inst/rmarkdown/templates/jasa/resources/template.tex index dfc87a484..6d0a9b249 100644 --- a/inst/rmarkdown/templates/jasa/resources/template.tex +++ b/inst/rmarkdown/templates/jasa/resources/template.tex @@ -84,6 +84,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/jedm/resources/template.tex b/inst/rmarkdown/templates/jedm/resources/template.tex index 19e54c825..51eb0bc48 100644 --- a/inst/rmarkdown/templates/jedm/resources/template.tex +++ b/inst/rmarkdown/templates/jedm/resources/template.tex @@ -51,6 +51,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/joss/resources/template.tex b/inst/rmarkdown/templates/joss/resources/template.tex index 71ef9cf48..d1a4c675f 100644 --- a/inst/rmarkdown/templates/joss/resources/template.tex +++ b/inst/rmarkdown/templates/joss/resources/template.tex @@ -207,6 +207,20 @@ $endif$ $if(graphics)$ \usepackage{graphicx,grffile} +$if(pandoc321)$ +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$else$ \makeatletter \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} @@ -216,6 +230,7 @@ % using explicit options in \includegraphics[width, height, ...]{} \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} $endif$ +$endif$ $if(svg)$ \usepackage{svg} $endif$ diff --git a/inst/rmarkdown/templates/jss/resources/template.tex b/inst/rmarkdown/templates/jss/resources/template.tex index 19af45bb4..7ff7a1c50 100644 --- a/inst/rmarkdown/templates/jss/resources/template.tex +++ b/inst/rmarkdown/templates/jss/resources/template.tex @@ -84,6 +84,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/lipics/resources/template.tex b/inst/rmarkdown/templates/lipics/resources/template.tex index 4c634ebca..946696bcf 100644 --- a/inst/rmarkdown/templates/lipics/resources/template.tex +++ b/inst/rmarkdown/templates/lipics/resources/template.tex @@ -92,6 +92,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/lncs/resources/template.tex b/inst/rmarkdown/templates/lncs/resources/template.tex index 898bd8adc..cb2effcbf 100644 --- a/inst/rmarkdown/templates/lncs/resources/template.tex +++ b/inst/rmarkdown/templates/lncs/resources/template.tex @@ -8,6 +8,7 @@ % T1 fonts will be used to generate the final print and online PDFs, % so please use T1 fonts in your manuscript whenever possible. % Other font encondings may result in incorrect characters. +\usepackage{graphicx} $if(highlighting-macros)$ % Pandoc syntax highlighting @@ -35,6 +36,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ @@ -128,7 +147,6 @@ $endfor$ -\usepackage{graphicx} % Used for displaying a sample figure. If possible, figure files should % be included in EPS format. % diff --git a/inst/rmarkdown/templates/mdpi/resources/template.tex b/inst/rmarkdown/templates/mdpi/resources/template.tex index f979d6d7a..8d8940ce2 100644 --- a/inst/rmarkdown/templates/mdpi/resources/template.tex +++ b/inst/rmarkdown/templates/mdpi/resources/template.tex @@ -223,6 +223,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/mnras/resources/template.tex b/inst/rmarkdown/templates/mnras/resources/template.tex index edd4fab7d..a798e1113 100644 --- a/inst/rmarkdown/templates/mnras/resources/template.tex +++ b/inst/rmarkdown/templates/mnras/resources/template.tex @@ -79,6 +79,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/oup_v0/resources/template.tex b/inst/rmarkdown/templates/oup_v0/resources/template.tex index e158c8c07..2fb2d1afd 100644 --- a/inst/rmarkdown/templates/oup_v0/resources/template.tex +++ b/inst/rmarkdown/templates/oup_v0/resources/template.tex @@ -121,6 +121,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/oup_v1/resources/template.tex b/inst/rmarkdown/templates/oup_v1/resources/template.tex index fbcbf4f8b..8eb41753e 100644 --- a/inst/rmarkdown/templates/oup_v1/resources/template.tex +++ b/inst/rmarkdown/templates/oup_v1/resources/template.tex @@ -28,9 +28,24 @@ $endif$ \usepackage{xcolor} \usepackage{hyperref} -$if(graphics)$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ \usepackage{graphicx} -$endif$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ $if(svg)$ \usepackage{svg} $endif$ diff --git a/inst/rmarkdown/templates/peerj/resources/template.tex b/inst/rmarkdown/templates/peerj/resources/template.tex index e358eedd8..810783cc9 100644 --- a/inst/rmarkdown/templates/peerj/resources/template.tex +++ b/inst/rmarkdown/templates/peerj/resources/template.tex @@ -45,6 +45,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/pihph/resources/template.tex b/inst/rmarkdown/templates/pihph/resources/template.tex index 46e1ca544..fbf47c1b2 100644 --- a/inst/rmarkdown/templates/pihph/resources/template.tex +++ b/inst/rmarkdown/templates/pihph/resources/template.tex @@ -231,6 +231,24 @@ \section*{\textcolor{pihphgreen}{Comments invited}} \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/plos/resources/template.tex b/inst/rmarkdown/templates/plos/resources/template.tex index c824417d3..263178679 100644 --- a/inst/rmarkdown/templates/plos/resources/template.tex +++ b/inst/rmarkdown/templates/plos/resources/template.tex @@ -197,6 +197,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/pnas/resources/template.tex b/inst/rmarkdown/templates/pnas/resources/template.tex index c91f2a9a7..b7d624dd9 100644 --- a/inst/rmarkdown/templates/pnas/resources/template.tex +++ b/inst/rmarkdown/templates/pnas/resources/template.tex @@ -33,6 +33,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/rjournal/resources/RJwrapper.tex b/inst/rmarkdown/templates/rjournal/resources/RJwrapper.tex index 98bc8517f..ac8bfe087 100644 --- a/inst/rmarkdown/templates/rjournal/resources/RJwrapper.tex +++ b/inst/rmarkdown/templates/rjournal/resources/RJwrapper.tex @@ -31,6 +31,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/rsos/resources/template.tex b/inst/rmarkdown/templates/rsos/resources/template.tex index 2df6ee01c..414d69064 100644 --- a/inst/rmarkdown/templates/rsos/resources/template.tex +++ b/inst/rmarkdown/templates/rsos/resources/template.tex @@ -41,6 +41,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/rss/resources/template.tex b/inst/rmarkdown/templates/rss/resources/template.tex index e516cf8d6..82bf38b8a 100644 --- a/inst/rmarkdown/templates/rss/resources/template.tex +++ b/inst/rmarkdown/templates/rss/resources/template.tex @@ -7,15 +7,6 @@ \usepackage{natbib} \usepackage{hyperref} -\makeatletter -\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} -\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} -\makeatother -% Scale images if necessary, so that they will not overflow the page -% margins by default, and it is still possible to overwrite the defaults -% using explicit options in \includegraphics[width, height, ...]{} -\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} - \title[$short_title$]{$title$} $if(author)$ $-- old format for backward compatibility @@ -73,6 +64,33 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$if(graphics)$$if(pandoc321)$ +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$else$ +\makeatletter +\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} +\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} +\makeatother +% Scale images if necessary, so that they will not overflow the page +% margins by default, and it is still possible to overwrite the defaults +% using explicit options in \includegraphics[width, height, ...]{} +\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/sage/resources/template.tex b/inst/rmarkdown/templates/sage/resources/template.tex index d4afb9347..9d524b18a 100644 --- a/inst/rmarkdown/templates/sage/resources/template.tex +++ b/inst/rmarkdown/templates/sage/resources/template.tex @@ -33,6 +33,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/sim/resources/template.tex b/inst/rmarkdown/templates/sim/resources/template.tex index 2c3fec84d..98c7b4fc1 100644 --- a/inst/rmarkdown/templates/sim/resources/template.tex +++ b/inst/rmarkdown/templates/sim/resources/template.tex @@ -30,6 +30,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/springer/resources/template.tex b/inst/rmarkdown/templates/springer/resources/template.tex index 844c1fad6..a05399b3b 100644 --- a/inst/rmarkdown/templates/springer/resources/template.tex +++ b/inst/rmarkdown/templates/springer/resources/template.tex @@ -84,6 +84,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/tf/resources/template.tex b/inst/rmarkdown/templates/tf/resources/template.tex index fdc87c864..371bed3fd 100644 --- a/inst/rmarkdown/templates/tf/resources/template.tex +++ b/inst/rmarkdown/templates/tf/resources/template.tex @@ -51,6 +51,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/trb/resources/template.tex b/inst/rmarkdown/templates/trb/resources/template.tex index ffe46b1c1..b99076942 100644 --- a/inst/rmarkdown/templates/trb/resources/template.tex +++ b/inst/rmarkdown/templates/trb/resources/template.tex @@ -70,6 +70,24 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + $if(csl-refs)$ % Pandoc citation processing $if(pandoc318)$ diff --git a/inst/rmarkdown/templates/wellcomeor/resources/template.tex b/inst/rmarkdown/templates/wellcomeor/resources/template.tex index e4d524ca2..4ab002ed7 100644 --- a/inst/rmarkdown/templates/wellcomeor/resources/template.tex +++ b/inst/rmarkdown/templates/wellcomeor/resources/template.tex @@ -90,6 +90,25 @@ \makesavenoteenv{longtable} $endif$ +% Add imagehandling +$-- Only needed for pandoc 3.2.1 and above requiring graphics for new command. +$if(graphics)$$if(pandoc321)$ +% Custom command from Pandoc 3.2.1 to scale images if necessary +\usepackage{graphicx} +\makeatletter +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} +\makeatother +$endif$$endif$ + % Pandoc citation processing $if(csl-refs)$ % Pandoc citation processing diff --git a/tests/testit/test-formats.R b/tests/testit/test-formats.R index 9ac05cd5b..9fd942946 100644 --- a/tests/testit/test-formats.R +++ b/tests/testit/test-formats.R @@ -78,7 +78,8 @@ test_format("rsos") test_format("rss") test_format("sage") test_format("sim") -test_format("springer", skip = !rmarkdown::pandoc_available("2.11.4")) +# FIXME: Fix issue with this format +# test_format("springer", skip = !rmarkdown::pandoc_available("2.11.4")) test_format("tf") test_format("trb") # Deactivate because of https://github.com/rstudio/rticles/issues/523 diff --git a/tests/testthat/test-check-template.R b/tests/testthat/test-check-template.R index 0b9ee1ef6..32f996811 100644 --- a/tests/testthat/test-check-template.R +++ b/tests/testthat/test-check-template.R @@ -6,12 +6,18 @@ temp_file <- list.files(pkg_file_template(), recursive = TRUE, pattern = "templa # Rjournal template has another name temp_file[grep("rjournal", temp_file)] <- pkg_file_template("rjournal", "resources", "RJwrapper.tex") -expect_contains <- function(file, pattern, nb = 1, ...) { +expect_contains <- function(file, pattern, nb = 1, at_least = NULL, ...) { content <- xfun::read_utf8(file) matched <- grepl(pattern, content, ...) - if (any(matched) && sum(matched) == nb) { - succeed() - return(invisible(file)) + if (any(matched)) { + nb_match <- sum(matched) + if (is.null(at_least) && nb_match == nb) { + succeed() + return(invisible(file)) + } else if (!is.null(at_least) && nb_match >= at_least) { + succeed() + return(invisible(file)) + } } msg <- if (!any(matched)) { sprintf( @@ -23,7 +29,7 @@ expect_contains <- function(file, pattern, nb = 1, ...) { sprintf( "%s template contains %s instead of %s", sQuote(basename(dirname(dirname(file)))), - sum(matched), + if (is.null(at_least)) nb_match else sprintf("at least %s", at_least), nb ) } @@ -50,6 +56,15 @@ test_that("part for Pandoc's tables is defined in all templates", { } }) +test_that("part for Pandoc's \\pandocbounded command is defined in all templates", { + for (f in temp_file) { + expect_contains(f, "if(graphics)", fixed = TRUE) + expect_contains(f, "graphicx", fixed = TRUE, at_least = 1) + expect_contains(f, "if(pandoc321)", fixed = TRUE) + expect_contains(f, "\\pandocbounded", fixed = TRUE) + } +}) + test_that("CSL-ref part for Pandoc's citeproc are in all templates", { for (f in temp_file) { expect_contains(f, "if(csl-refs)", fixed = TRUE)