loading...

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.

new_labelling(
  type = c("arabic", "roman"),
  string_html = paste0("<style>.++++-%%%%::after{content:\"####\"}</style>",
    "<span class=\"figheader\">Figure\\ ####: </span>@@@@"),
  string_latex = "@@@@",
  string_word = "[Figure\\ ####:]{#++++:%%%%} @@@@",
  string_ref_html = "<a class=\"++++-%%%%\" href=\"#++++:%%%%\"></a>",
  string_ref_latex = "\\ref{++++:%%%%}",
  string_ref_word = "[####](#++++:%%%%)",
  name = "fig"
)

newLabelling(
  type = c("arabic", "roman"),
  string_html = paste0("<style>.++++-%%%%::after{content:\"####\"}</style>",
    "<span class=\"figheader\">Figure\\ ####: </span>@@@@"),
  string_latex = "@@@@",
  string_word = "[Figure\\ ####:]{#++++:%%%%} @@@@",
  string_ref_html = "<a class=\"++++-%%%%\" href=\"#++++:%%%%\"></a>",
  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).

Author

Philippe Grosjean

Examples

# 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")
#> [1] "<style>.fig-a_label::after{content:\"1\"}</style><span class=\"figheader\">Figure\\ 1: </span>A caption"
# Produce a reference to that figure
fig$a_label
#> [1] "<a class=\"fig-a_label\" href=\"#fig:a_label\"></a>"