1

我正在为打算提交给 CRAN 的包裹写一个小插图。我遇到的一个问题是,某些函数及其输入参数可能会变得很长,以至于它们的示例代码会超出页面。

我担心这是 LaTeX 的一个细致问题,因为我之前已经发生过很多次了。但是,我希望所有示例代码对用户可见。幸运的是,我放在小插图中的示例代码都不应该自动运行。因此,我在 R 块中有一个 eval=FALSE 表达式。

作为故障排除解决方案的(可能的黑客?),我刚刚在代码中手动插入了一个无论如何都不会运行的换行符。这允许示例代码不会在页面外运行,并且不会影响无论如何不会自动运行的示例代码的功能。

这个“解决方案”是否符合 CRAN 标准?如果不是,我可以尝试考虑什么其他解决方案来解决这个问题?

下面是我的 MWE:

\documentclass{article}
\setlength{\parindent}{0pt} % Remove indent at new paragraphs
\setcounter{secnumdepth}{0}  % Remove section numbering at certain depth
\usepackage[round,sort]{natbib}
\usepackage{fixltx2e}
\usepackage{graphicx}   % For external pictures
\usepackage{float}
\usepackage{subfig} % Add subfigures within figures
\usepackage{verbatim}
\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}
\usepackage{amssymb,amsbsy,amsmath}
\usepackage{epsfig}
\usepackage[left=3cm,top=3cm,bottom=3.5cm,right=3cm]{geometry} % For easy document margins
\usepackage{fancyhdr} % For customization of header/footer
\usepackage{adjustbox}
\numberwithin{equation}{section} % Equation numbers relative to sections
\begin{document}
\sloppy

<<include=FALSE>>=
library(knitr)
opts_chunk$set(
concordance=TRUE
)
@

<<echo=FALSE>>=
rm(list=ls())
library(knitr)
@ 

\section{Examples}

\subsection{Easy Example}

Here is an example you can run below:

<<eval=FALSE>>=
example1 = function1("it does not surpass the line")
@

Here is a second example you can run below. Unfortunately, you cannot even see teh whole example code because it runs off the page:

<<eval=FALSE>>=
example2 = function2(input1="this example", input2 = "has a lot of inputs", input3="which makes it impossible", input4 = "to fit on the same line")
@

Can I fix this second example by forcing a break as such?:

<<eval=FALSE>>=
example2 = function2(input1="this example", input2 = "has a lot of inputs",
input3="which makes it impossible", input4 = "to fit on the same line")
@

\end{document}
4

0 回答 0