Learn R Programming

svSweave (version 1.0.0)

new_labelling: Reference figures, tables and equations in R Markdown documents

Description

These functions return closures that allow for constructing a series of numbered items and to reference them. The number is create the first time a label is encountered, and provided again for further use of the same label.

Usage

new_labelling(
  type = c("arabic", "roman"),
  string_html = paste0("",
    "Figure\\ ####: @@@@"),
  string_latex = "@@@@",
  string_word = "[Figure\\ ####:]{#++++:%%%%} @@@@",
  string_ref_html = "",
  string_ref_latex = "\\ref{++++:%%%%}",
  string_ref_word = "[####](#++++:%%%%)",
  name = "fig"
)

newLabelling( type = c("arabic", "roman"), string_html = paste0("", "Figure\\ ####: @@@@"), string_latex = "@@@@", string_word = "[Figure\\ ####:]{#++++:%%%%} @@@@", string_ref_html = "", string_ref_latex = "\\ref{++++:%%%%}", string_ref_word = "[####](#++++:%%%%)", name = "fig" )

fig( caption = "", label = knitr::opts_current$get("label"), ref = NULL, reset = FALSE )

tab( caption = "", label = knitr::opts_current$get("label"), ref = NULL, reset = FALSE )

eq(label, ref, reset = FALSE)

Arguments

type

The type of numbering (arabic or roman).

string_html

The string prototyping the legend, with ++++ being the name (fig by default) @@ being a placeholder for the text, #### as a placeholder for the number, or %%%% as a placeholder for the label.

string_latex

Idem for LaTeX.

string_word

Idem for Word.

string_ref_html

Idem for reference in HTML format.

string_ref_latex

Idem for reference in LaTeX format.

string_ref_word

Idem for reference in Word format.

name

The name to use before the number, e.g., "Fig." to get "Fig. 1" as cross-reference text for the first figure. If you provide name = NULL, only the number is produced.

caption

The test of the caption.

label

A short string uniquely identifying the item within the collection. To set a label in and equation, give a name instead of a string.

ref

The reference to the label.

reset

If TRUE, the collection is reset. Useful if you want to restart numbering at the beginning of each chapter.

Value

The function returns a caption if text = is provided, or an anchor if it is missing. If text= contains a name, it returns a link. Same for the label= for eq(): if it is a text, a couple label + tag to place inside display equations is produced, and if it is a name, a link is provided. new_labelling() creates a new labelling function, which has the same arguments as fig().

Details

A new labelling type is created using new_labelling() which is a function factory (a function that creates functions).

Examples

Run this code
# NOT RUN {
# These function are supposed to be used in an R Markdown document
# see the svSweave vignette
# Produce a caption that contains the required code to number and reference
# a figure in HTML documents
fig("A caption", label = "a_label")
# Produce a reference to that figure
fig$a_label
# }

Run the code above in your browser using DataLab