I'm working on an introductory course for the R-language in Latex, so I'm trying to write a Latex function that displays the R-function. This is what I've got:
\makeatletter
\newcommand{\fun}[3]{
\begin{tcolorbox}[top = 0mm, bottom = 0mm, left = 0mm, right = 0mm, colback=green!5,colframe=vubgreen,title=#3]
\begin{tabular}{p{.2\textwidth}p{.04\textwidth}p{.68\textwidth}}
{\tt#1(}\\\@for\x:=#2\do{\x\\}{\tt$\quad$)}
\end{tabular}
\end{tcolorbox}}
\makeatother
So, this function accepts three parameters: the name of the R-function, a list of R-parameters, and a description, with each R-parameter:
\renewcommand{\arg}[3][]{
{\tt$\quad$#2}&}
So you can write for example:
\fun{hist}
{
\arg{x}{Vector.},
\arg{freq = TRUE}{Use absolute frequencies.}
}
{Draw a histogram.}
Now I'm having a few small problems to get it completely right: - The opening round bracket has to be on the same line as the first parameter (so the line under the first function. - The closing round bracket has to be right behind the last parameter (NOT behind the description of the parameter). - Behind each parameter there has to be a comma, except after the last one. - However: if a function has no parameters, opening and closing round bracket have to be on the same line as the name of the function.
Packages used (not all relevant for this example):
\usepackage{array}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{answers}
\usepackage{graphicx}
\usepackage{tcolorbox}
\usepackage{color}
\usepackage{xcolor}
\usepackage{epstopdf}
\usepackage[dutch]{babel}
\usepackage{anysize}
\usepackage[parfill]{parskip}
\usepackage{hyperref}
\usepackage{longtable}
I think this seems like a challenge, even for the TeXperts over here. All help is really appreciated!
{}) rather than add backticks before/after the code. Welcome! – Manuel Jan 23 '14 at 13:59knitr(http://yihui.name/knitr/), which allows you to write executable R in your document. That will guarantee the semantic correctness of your code as well as its proper prettyprinting. – Ethan Bolker Jan 23 '14 at 15:00<<>>=(optionally with many very useful parameters) and where R end (a line with only@) or alternatively, to just print the value or some R object of some function, you can use a\Sexpr{}like\Sexpr{round(log(pi),1)}(that will print "1.1") . There any examples of use of knitr in this site. You do not know what you will lose if you persist in your wrong belief ... – Fran Jan 30 '20 at 07:38