RJournal.sty 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. % Package `RJournal' to use with LaTeX2e
  2. % Copyright (C) 2010 by the R Foundation
  3. % Copyright (C) 2013 by the R Journal
  4. %
  5. % Originally written by Kurt Hornik and Friedrich Leisch with subsequent
  6. % edits by the editorial board
  7. \NeedsTeXFormat{LaTeX2e}[1995/12/01]
  8. \ProvidesPackage{RJournal}[2013/08/27 v0.13 RJournal package]
  9. \RequirePackage{tikz}
  10. % Overall page layout, fonts etc -----------------------------------------------
  11. % Issues of of \emph{The R Journal} are created from the standard \LaTeX{}
  12. % document class \pkg{report}.
  13. \RequirePackage{geometry}
  14. \geometry{a4paper,
  15. textwidth=14cm, top=1cm, bottom=1cm,
  16. includehead,includefoot,centering,
  17. footskip=1.5cm}
  18. \raggedbottom
  19. \RequirePackage{fancyhdr}
  20. \fancyhead{}
  21. \fancyheadoffset{2cm}
  22. \fancyhead[L]{\textsc{\RJ@sectionhead}}
  23. \fancyhead[R]{\thepage}
  24. \fancyfoot{}
  25. \fancyfoot[L]{The R Journal Vol. \RJ@volume/\RJ@number, \RJ@month}
  26. \fancyfoot[R]{ISSN 2073-4859}
  27. \pagestyle{fancy}
  28. % We use the following fonts (all with T1 encoding):
  29. %
  30. % rm & palatino
  31. % tt & inconsolata
  32. % sf & helvetica
  33. % math & palatino
  34. \RequirePackage{microtype}
  35. \RequirePackage[scaled=0.92]{helvet}
  36. \RequirePackage{palatino,mathpazo}
  37. \RequirePackage[scaled=1.02]{inconsolata}
  38. \RequirePackage[T1]{fontenc}
  39. \RequirePackage[hyphens]{url}
  40. \RequirePackage[pagebackref]{hyperref}
  41. \renewcommand{\backref}[1]{[p#1]}
  42. % Dark blue colour for all links
  43. \RequirePackage{color}
  44. \definecolor{link}{rgb}{0.45,0.51,0.67}
  45. \hypersetup{
  46. colorlinks,%
  47. citecolor=link,%
  48. filecolor=link,%
  49. linkcolor=link,%
  50. urlcolor=link
  51. }
  52. % Give the text a little room to breath
  53. \setlength{\parskip}{3pt}
  54. \RequirePackage{setspace}
  55. \setstretch{1.05}
  56. % Issue and article metadata ---------------------------------------------------
  57. % Basic front matter information about the issue: volume, number, and
  58. % date.
  59. \newcommand{\volume}[1]{\def\RJ@volume{#1}}
  60. \newcommand{\volnumber}[1]{\def\RJ@number{#1}}
  61. \renewcommand{\month}[1]{\def\RJ@month{#1}}
  62. \renewcommand{\year}[1]{\def\RJ@year{#1}}
  63. % Individual articles correspond to
  64. % chapters, and are contained in |article| environments. This makes it
  65. % easy to have figures counted within articles and hence hyperlinked
  66. % correctly.
  67. % An article has an author, a title, and optionally a subtitle. We use
  68. % the obvious commands for specifying these. Articles will be put in certain
  69. % journal sections, named by \sectionhead.
  70. \newcommand {\sectionhead} [1]{\def\RJ@sectionhead{#1}}
  71. \renewcommand{\author} [1]{\def\RJ@author{#1}}
  72. \renewcommand{\title} [1]{\def\RJ@title{#1}}
  73. \newcommand {\subtitle} [1]{\def\RJ@subtitle{#1}}
  74. % Control appearance of titles: make slightly smaller than usual, and
  75. % suppress section numbering. See http://tex.stackexchange.com/questions/69749
  76. % for why we don't use \setcounter{secnumdepth}{-1}
  77. \usepackage[medium]{titlesec}
  78. \usepackage{titletoc}
  79. \titleformat{\section} {\normalfont\large\bfseries}{}{0em}{}
  80. \titleformat{\subsection}{\normalfont\normalsize\bfseries}{}{0em}{}
  81. \titlecontents{chapter} [0em]{}{}{}{\titlerule*[1em]{.}\contentspage}
  82. % Article layout ---------------------------------------------------------------
  83. % Environment |article| clears the article header information at its beginning.
  84. % We use |\FloatBarrier| from the placeins package to keep floats within
  85. % the article.
  86. \RequirePackage{placeins}
  87. \newenvironment{article}{\author{}\title{}\subtitle{}\FloatBarrier}{\FloatBarrier}
  88. % Refereed articles should have an abstract, so we redefine |\abstract| to
  89. % give the desired style
  90. \renewcommand{\abstract}[1]{%
  91. \setstretch{1}%
  92. \noindent%
  93. \small%
  94. \textbf{Abstract} #1
  95. }
  96. % The real work is done by a redefined version of |\maketitle|. Note
  97. % that even though we do not want chapters (articles) numbered, we
  98. % need to increment the chapter counter, so that figures get correct
  99. % labelling.
  100. \renewcommand{\maketitle}{%
  101. \noindent
  102. \chapter{\RJ@title}\refstepcounter{chapter}
  103. \ifx\empty\RJ@subtitle
  104. \else
  105. \noindent\textbf{\RJ@subtitle}
  106. \par\nobreak\addvspace{\baselineskip}
  107. \fi
  108. \ifx\empty\RJ@author
  109. \else
  110. \noindent\textit{\RJ@author}
  111. \par\nobreak\addvspace{\baselineskip}
  112. \fi
  113. \@afterindentfalse\@nobreaktrue\@afterheading
  114. }
  115. % Now for some ugly redefinitions. We do not want articles to start a
  116. % new page. (Actually, we do, but this is handled via explicit
  117. % \newpage
  118. %
  119. % The name@of@eq is a hack to get hyperlinks to equations to work
  120. % within each article, even though there may be multiple eq.(1)
  121. % \begin{macrocode}
  122. \renewcommand\chapter{\secdef\RJ@chapter\@schapter}
  123. \providecommand{\nohyphens}{%
  124. \hyphenpenalty=10000\exhyphenpenalty=10000\relax}
  125. \newcommand{\RJ@chapter}{%
  126. \edef\name@of@eq{equation.\@arabic{\c@chapter}}%
  127. \renewcommand{\@seccntformat}[1]{}%
  128. \@startsection{chapter}{0}{0mm}{%
  129. -2\baselineskip \@plus -\baselineskip \@minus -.2ex}{\p@}{%
  130. \phantomsection\normalfont\huge\bfseries\raggedright}}
  131. % Book reviews should appear as sections in the text and in the pdf bookmarks,
  132. % however we wish them to appear as chapters in the TOC. Thus we define an
  133. % alternative to |\maketitle| for reviews.
  134. \newcommand{\review}[1]{
  135. \pdfbookmark[1]{#1}{#1}
  136. \section*{#1}
  137. \addtocontents{toc}{\protect\contentsline{chapter}{#1}{\thepage}{#1.1}}
  138. }
  139. % We want bibliographies as starred sections within articles.
  140. %
  141. \RequirePackage[sectionbib,round]{natbib}
  142. \bibliographystyle{abbrvnat}
  143. % Equations, figures and tables are counted within articles, but we do
  144. % not show the article number. For equations it becomes a bit messy to avoid
  145. % having hyperref getting it wrong.
  146. % \numberwithin{equation}{chapter}
  147. \renewcommand{\theequation}{\@arabic\c@equation}
  148. \renewcommand{\thefigure}{\@arabic\c@figure}
  149. \renewcommand{\thetable}{\@arabic\c@table}
  150. % Issue layout -----------------------------------------------------------------
  151. % Need to provide our own version of |\tableofcontents|. We use the
  152. % tikz package to get the rounded rectangle. Notice that |\section*|
  153. % is really the same as |\chapter*|.
  154. \renewcommand{\contentsname}{Contents}
  155. \renewcommand\tableofcontents{%
  156. \vspace{1cm}
  157. \section*{\contentsname}
  158. { \@starttoc{toc} }
  159. }
  160. \renewcommand{\titlepage}{%
  161. \thispagestyle{empty}
  162. \hypersetup{
  163. pdftitle={The R Journal Volume \RJ@volume/\RJ@number, \RJ@month \RJ@year},%
  164. pdfauthor={R Foundation for Statistical Computing},%
  165. }
  166. \noindent
  167. \begin{center}
  168. \fontsize{50pt}{50pt}\selectfont
  169. The \raisebox{-8pt}{\includegraphics[height=77pt]{Rlogo-4}}\hspace{10pt}
  170. Journal
  171. \end{center}
  172. {\large \hfill Volume \RJ@volume/\RJ@number, \RJ@month{} \RJ@year \quad}
  173. \rule{\textwidth}{1pt}
  174. \begin{center}
  175. {\Large A peer-reviewed, open-access publication of the \\
  176. R Foundation for Statistical Computing}
  177. \end{center}
  178. % And finally, put in the TOC box. Note the way |tocdepth| is adjusted
  179. % before and after producing the TOC: thus, we can ensure that only
  180. % articles show up in the printed TOC, but that in the PDF version,
  181. % bookmarks are created for sections and subsections as well (provided
  182. % that the non-starred forms are used).
  183. \setcounter{tocdepth}{0}
  184. \tableofcontents
  185. \setcounter{tocdepth}{2}
  186. \clearpage
  187. }
  188. % Text formatting --------------------------------------------------------------
  189. \newcommand{\R}{R}
  190. \newcommand{\address}[1]{\addvspace{\baselineskip}\noindent\emph{#1}}
  191. \newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}}
  192. % Simple font selection is not good enough. For example, |\texttt{--}|
  193. % gives `\texttt{--}', i.e., an endash in typewriter font. Hence, we
  194. % need to turn off ligatures, which currently only happens for commands
  195. % |\code| and |\samp| and the ones derived from them. Hyphenation is
  196. % another issue; it should really be turned off inside |\samp|. And
  197. % most importantly, \LaTeX{} special characters are a nightmare. E.g.,
  198. % one needs |\~{}| to produce a tilde in a file name marked by |\file|.
  199. % Perhaps a few years ago, most users would have agreed that this may be
  200. % unfortunate but should not be changed to ensure consistency. But with
  201. % the advent of the WWW and the need for getting `|~|' and `|#|' into
  202. % URLs, commands which only treat the escape and grouping characters
  203. % specially have gained acceptance
  204. \DeclareRobustCommand\code{\bgroup\@noligs\@codex}
  205. \def\@codex#1{\texorpdfstring%
  206. {{\normalfont\ttfamily\hyphenchar\font=-1 #1}}%
  207. {#1}\egroup}
  208. \newcommand{\kbd}[1]{{\normalfont\texttt{#1}}}
  209. \newcommand{\key}[1]{{\normalfont\texttt{\uppercase{#1}}}}
  210. \DeclareRobustCommand\samp{`\bgroup\@noligs\@sampx}
  211. \def\@sampx#1{{\normalfont\texttt{#1}}\egroup'}
  212. \newcommand{\var}[1]{{\normalfont\textsl{#1}}}
  213. \let\env=\code
  214. \newcommand{\file}[1]{{`\normalfont\textsf{#1}'}}
  215. \let\command=\code
  216. \let\option=\samp
  217. \newcommand{\dfn}[1]{{\normalfont\textsl{#1}}}
  218. % \acronym is effectively disabled since not used consistently
  219. \newcommand{\acronym}[1]{#1}
  220. \newcommand{\strong}[1]{\texorpdfstring%
  221. {{\normalfont\fontseries{b}\selectfont #1}}%
  222. {#1}}
  223. \let\pkg=\strong
  224. \newcommand{\CRANpkg}[1]{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}%
  225. \let\cpkg=\CRANpkg
  226. \newcommand{\ctv}[1]{\href{http://CRAN.R-project.org/view=#1}{\emph{#1}}}
  227. \newcommand{\BIOpkg}[1]{\href{http://www.bioconductor.org/packages/release/bioc/html/#1.html}{\pkg{#1}}}
  228. % Example environments ---------------------------------------------------------
  229. \RequirePackage{fancyvrb}
  230. \RequirePackage{alltt}
  231. \DefineVerbatimEnvironment{example}{Verbatim}{}
  232. \renewenvironment{example*}{\begin{alltt}}{\end{alltt}}
  233. % Support for output from Sweave, and generic session style code
  234. % These used to have fontshape=sl for Sinput/Scode/Sin, but pslatex
  235. % won't use a condensed font in that case.
  236. \DefineVerbatimEnvironment{Sinput}{Verbatim}{fontsize=\small}
  237. \DefineVerbatimEnvironment{Soutput}{Verbatim}{fontsize=\small}
  238. \DefineVerbatimEnvironment{Scode}{Verbatim}{fontsize=\small}
  239. \DefineVerbatimEnvironment{Sin}{Verbatim}{fontsize=\small}
  240. \DefineVerbatimEnvironment{Sout}{Verbatim}{fontsize=\small}
  241. \newenvironment{Schunk}{}{}
  242. % Mathematics ------------------------------------------------------------------
  243. % The implementation of |\operatorname| is similar to the mechanism
  244. % \LaTeXe{} uses for functions like sin and cos, and simpler than the
  245. % one of \AmSLaTeX{}. We use |\providecommand| for the definition in
  246. % order to keep the one of the \pkg{amstex} if this package has
  247. % already been loaded.
  248. % \begin{macrocode}
  249. \providecommand{\operatorname}[1]{%
  250. \mathop{\operator@font#1}\nolimits}
  251. \RequirePackage{amsfonts}
  252. \renewcommand{\P}{%
  253. \mathop{\operator@font I\hspace{-1.5pt}P\hspace{.13pt}}}
  254. \newcommand{\E}{%
  255. \mathop{\operator@font I\hspace{-1.5pt}E\hspace{.13pt}}}
  256. \newcommand{\VAR}{\operatorname{var}}
  257. \newcommand{\COV}{\operatorname{cov}}
  258. \newcommand{\COR}{\operatorname{cor}}
  259. % Figures ----------------------------------------------------------------------
  260. \RequirePackage[font=small,labelfont=bf]{caption}
  261. % Wide environments for figures and tables -------------------------------------
  262. \RequirePackage{environ}
  263. % An easy way to make a figure span the full width of the page
  264. \NewEnviron{widefigure}[1][]{
  265. \begin{figure}[#1]
  266. \advance\leftskip-2cm
  267. \begin{minipage}{\dimexpr\textwidth+4cm\relax}%
  268. \captionsetup{margin=2cm}
  269. \BODY
  270. \end{minipage}%
  271. \end{figure}
  272. }
  273. \NewEnviron{widetable}[1][]{
  274. \begin{table}[#1]
  275. \advance\leftskip-2cm
  276. \begin{minipage}{\dimexpr\textwidth+4cm\relax}%
  277. \captionsetup{margin=2cm}
  278. \BODY
  279. \end{minipage}%
  280. \end{table}
  281. }