Skip to content

Commit

Permalink
Adds package option enables, adds a few new hooks to template, and cl…
Browse files Browse the repository at this point in the history
…eans up a few areas
  • Loading branch information
coatless committed Jan 21, 2017
1 parent f23d093 commit 136c182
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 26 deletions.
79 changes: 77 additions & 2 deletions R/ieee_article.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
#' \href{http://www.ieee.org/publications_standards/publications/authors/author_templates.html}{http://www.ieee.org/publications_standards/publications/authors/author_templates.html}.
#'
#' @inheritParams rmarkdown::pdf_document
#' @param draftmode Specify the draft mode to control spacing and whether images
#' should be rendered. Valid options are: \code{"final"} (default), \code{"draft"},
#' \code{"draftcls"}, or \code{"draftclsnofoot"}.
#' @param hyphenfixes A \code{character} value that provides the correct
#' hyphenations for ambiguous words. Separate new words with spaces.
#' @param IEEEspecialpaper A \code{character} value containing the publication's
#' special paper designation.
#' @param with_ifpdf A \code{logical} value turning on (\code{TRUE}) or off
#' (\code{FALSE}) the \code{ifpdf} LaTeX package.
#' @param with_cite A \code{logical} value turning on (\code{TRUE}) or off
#' (\code{FALSE}) the \code{cite} LaTeX package.
#' @param with_amsmath A \code{logical} value turning on (\code{TRUE}) or off
#' (\code{FALSE}) the \code{amsmath} LaTeX package.
#' @param with_algorithmic A \code{logical} value turning on (\code{TRUE}) or
#' off (\code{FALSE}) the \code{algorithmic} LaTeX package.
#' @param with_subfig A \code{logical} value turning on (\code{TRUE}) or off
#' (\code{FALSE}) the \code{subfig} LaTeX package.
#' @param with_array A \code{logical} value turning on (\code{TRUE}) or off
#' (\code{FALSE}) the \code{array} LaTeX package.
#' @param with_dblfloatfix A \code{logical} value turning on (\code{TRUE}) or
#' off (\code{FALSE}) the \code{dblfloatfix} LaTeX package.
#' @param ... Additional arguments to \code{rmarkdown::pdf_document}
#'
#' @return R Markdown output format to pass to
Expand All @@ -16,11 +37,65 @@
#' draft("MyArticle.Rmd", template = "ieee_article", package = "rticles")
#' }
#'
#' @details
#' Presently, only the \code{"conference"} paper mode offered by the
#' \code{IEEEtran.cls} is supported.
#'
#' @references
#' Shell, Michael. "How to use the IEEEtran LATEX class." Journal of LATEX Class
#' Files 1.11 (2002): 10-20.
#' \url{http://mirrors.rit.edu/CTAN/macros/latex/contrib/IEEEtran/IEEEtran_HOWTO.pdf}
#' @export
ieee_article <- function(...,
keep_tex = TRUE,
md_extensions = c("-autolink_bare_uris")) {
draftmode = c("final", "draft", "draftcls",
"draftclsnofoot"),
hyphenfixes = "op-tical net-works semi-conduc-tor",
IEEEspecialpaper = "",
with_ifpdf = FALSE,
with_cite = FALSE,
with_amsmath = FALSE,
with_algorithmic = FALSE,
with_subfig = FALSE,
with_array = FALSE,
with_dblfloatfix = FALSE,
keep_tex = TRUE,
md_extensions = c("-autolink_bare_uris")) {

args <- c()

draftmode <- match.arg(draftmode)
args <- c(args, "draftmode" = draftmode)

args <- c(args, "hyphenfixes" = hyphenfixes)

# Avoid declaration of pandoc variable if field is empty
if(nchar(IEEEspecialpaper) > 1){
args <- c(args, "IEEEspecialpaper" = IEEEspecialpaper)
}

plist <- c("with_ifpdf" = with_ifpdf,
"with_cite" = with_cite,
"with_amsmath" = with_amsmath,
"with_algorithmic" = with_algorithmic,
"with_subfig" = with_subfig,
"with_array" = with_array,
"with_dblfloatfix" = with_dblfloatfix)

# Obtain only variables that should be turned on
requested_withs <- sapply(plist, isTRUE)

args <- c(args, plist[requested_withs])

# pandoc_variable_arg not exported from rmarkdown
pandoc_arg_variable = function(var_name, value){
c("-V", paste0(var_name, "=", value))
}

# Convert to pandoc arguments
pandoc_arg_list <- mapply(pandoc_arg_variable, names(args), args)

inherit_pdf_document(...,
pandoc_args = pandoc_arg_list,
template = find_resource("ieee_article", "template.tex"),
keep_tex = keep_tex,
md_extensions = md_extensions)
Expand Down
6 changes: 6 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
rticles 0.2.0.9000
---------------------------------------------------------------------

- Add Institute of Electrical and Electronics Engineers (IEEE) IEEEtrans
template for Conferences


rticles 0.2
---------------------------------------------------------------------
Expand Down
85 changes: 65 additions & 20 deletions inst/rmarkdown/templates/ieee_article/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
% The testflow support page is at:
% http://www.michaelshell.org/tex/testflow/

\documentclass[conference]{IEEEtran}
\documentclass[conference,$if(fontsize)$$fontsize$,$endif$$if(draftmode)$$draftmode$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{IEEEtran}
% Some Computer Society conferences also require the compsoc mode option,
% but others use the standard conference format.
%
Expand All @@ -68,6 +68,9 @@

% *** MISC UTILITY PACKAGES ***
%
$if(with_ifpdf)$
\usepackage{ifpdf}
$endif$
%\usepackage{ifpdf}
% Heiko Oberdiek's ifpdf.sty is very useful if you need conditional
% compilation based on whether the output is pdf or dvi.
Expand All @@ -91,6 +94,9 @@

% *** CITATION PACKAGES ***
%
$if(with_cite)$
\usepackage{cite}
$endif$
%\usepackage{cite}
% cite.sty was written by Donald Arseneau
% V1.6 and later of IEEEtran pre-defines the format of the cite.sty package
Expand Down Expand Up @@ -158,6 +164,10 @@

% *** MATH PACKAGES ***
%
$if(with_amsmath)$
\usepackage{amsmath}
\interdisplaylinepenalty=2500
$endif$
%\usepackage{amsmath}
% A popular package from the American Mathematical Society that provides
% many useful and powerful commands for dealing with mathematics.
Expand All @@ -176,6 +186,9 @@

% *** SPECIALIZED LIST PACKAGES ***
%
$if(with_algorithmic)$
\usepackage{algorithmic}
$endif$
%\usepackage{algorithmic}
% algorithmic.sty was written by Peter Williams and Rogerio Brito.
% This package provides an algorithmic environment fo describing algorithms.
Expand All @@ -196,6 +209,9 @@

% *** ALIGNMENT PACKAGES ***
%
$if(with_array)$
\usepackage{array}
$endif$
%\usepackage{array}
% Frank Mittelbach's and David Carlisle's array.sty patches and improves
% the standard LaTeX2e array and tabular environments to provide better
Expand Down Expand Up @@ -243,6 +259,10 @@

% *** FLOAT PACKAGES ***
%
$if(with_dblfloatfix)$
\usepackage{dblfloatfix}
$endif$

%\usepackage{fixltx2e}
% fixltx2e, the successor to the earlier fix2col.sty, was written by
% Frank Mittelbach and David Carlisle. This package corrects a few problems
Expand Down Expand Up @@ -312,7 +332,7 @@

$if(natbib)$
\usepackage{natbib}
\bibliographystyle{plainnat}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(biblatex)$
\usepackage{biblatex}
Expand All @@ -324,7 +344,7 @@
$endif$

$if(tables)$
\usepackage{longtable}
\usepackage{longtable,booktabs}
$endif$
$if(graphics)$
\usepackage{graphicx}
Expand All @@ -341,21 +361,30 @@

\usepackage[unicode=true]{hyperref}

\hypersetup{breaklinks=true,
bookmarks=true,
pdfauthor={$author-meta$},
\hypersetup{
$if(title-meta)$
pdftitle={$title-meta$},
$endif$
$if(author-meta)$
pdfauthor={$author-meta$},
$endif$
$if(keywords)$
pdfkeywords={$for(keywords)$$keywords$$sep$, $endfor$},
$endif$
$if(colorlinks)$
colorlinks=true,
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
pdfborder={0 0 0}}
linkcolor=$if(linkcolor)$$linkcolor$$else$Magenta$endif$,
citecolor=$if(citecolor)$$citecolor$$else$Blue$endif$,
urlcolor=$if(urlcolor)$$urlcolor$$else$Blue$endif$,
$else$
pdfborder={0 0 0},
$endif$
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls

$for(header-includes)$
$header-includes$
$endfor$
% Pandoc toggle for numbering sections (defaults to be off)
$if(numbersections)$
\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$}
$else$
\setcounter{secnumdepth}{0}
$endif$
Expand All @@ -368,11 +397,9 @@
%% END MY ADDITIONS %%


% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\hyphenation{$hyphenfixes$}

\begin{document}

%
% paper title
% Titles are generally capitalized except for words such as a, an, and, as,
Expand All @@ -389,11 +416,13 @@
\author{
$for(author)$
\IEEEauthorblockN{$author.name$}
\IEEEauthorblockA{$author.affiliation$}
{$author.department$}\\
{$author.location$}\\
{$author.email$}
\and $endfor$
\IEEEauthorblockA{$author.affiliation$\\
$author.department$\\
$author.location$\\
$author.email$
}
$sep$\and
$endfor$
}

% conference papers do not typically use \thanks and this command
Expand Down Expand Up @@ -438,6 +467,18 @@

% no keywords

% use for special paper notices

$if(IEEEspecialpaper)$
\IEEEspecialpapernotice{$IEEEspecialpaper$}
$endif$


% make the title area
\maketitle

% no keywords

% For peer review papers, you can put extra information on the cover
% page as needed:
% \ifCLASSOPTIONpeerreview
Expand All @@ -448,6 +489,10 @@
% creates the second title. It will be ignored for other modes.
\IEEEpeerreviewmaketitle

$for(include-before)$
$include-before$

$endfor$

$body$

Expand Down
4 changes: 2 additions & 2 deletions inst/rmarkdown/templates/ieee_article/skeleton/mybibfile.bib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@article{Dirac1953888,
title = "The lorentz transformation and absolute time",
journal = "Physica ",
journal = "Physica",
volume = "19",
number = "1-12",
number = "1--12",
pages = "888--896",
year = "1953",
doi = "10.1016/S0031-8914(53)80099-6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ author:
affiliation: University of Nevada
department: Civil Engineering
location: Las Vegas, Nevada 89119
email: daniel.emaasit@gmail.com
email: daniel.emaasit@gmail.com
- name: Alice Wonderland
affiliation: Another University
department: Your Department
Expand Down
47 changes: 46 additions & 1 deletion man/ieee_article.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test_formats.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test_format("rjournal_article", file_check = FALSE)
test_format("acs_article", os_skip = "windows")
test_format("pnas_article")
test_format("aea_article")
test_format("ieee_article")



0 comments on commit 136c182

Please sign in to comment.