GeneralCreating Function for R-Functions

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
m00se
Posts: 1
Joined: Thu Jan 09, 2014 9:41 pm

Creating Function for R-Functions

Post by m00se »

Hi

I'm working on an introductory course for the R-language in LaTeX, so I'm trying to write a function that displays the R-function. This is what I've got:

Code: Select all

\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:

Code: Select all

\renewcommand{\arg}[3][]{
  {\tt$\quad$#2}&&#3}
So you can write for example:

Code: Select all

\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):

Code: Select all

\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!


Also posted to {TeX} SX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply