getLatexStrWidth: Obtain Font Metrics from LaTeX

View source: R/latexStrWidth.R

getLatexStrWidthR Documentation

Obtain Font Metrics from LaTeX

Description

These functions calculate the width of a character or string as it would appear after being compiled by LaTeX.

Usage

getLatexStrWidth(
  texString,
  cex = 1,
  face = 1,
  engine = getOption("tikzDefaultEngine"),
  documentDeclaration = getOption("tikzDocumentDeclaration"),
  packages,
  verbose = interactive(),
  diagnose = FALSE
)

getLatexCharMetrics(
  charCode,
  cex = 1,
  face = 1,
  engine = getOption("tikzDefaultEngine"),
  documentDeclaration = getOption("tikzDocumentDeclaration"),
  packages,
  verbose = interactive()
)

Arguments

texString

An arbitrary string for which the width is to be calculated. May contain LaTeX markup.

cex

a real number that specifies a scaling factor that is to be applied to device output.

face

an integer in the range 1:5 that specifies the font face to use. See par for details.

engine

a string specifying which TeX engine to use. Possible values are 'pdftex', 'xetex' and 'luatex'. See the Unicode section of tikzDevice-package for details.

documentDeclaration

See the sections "Options That Affect Package Behavior" and "Font Size Calculations" of tikzDevice-package for more details.

packages

See the section "Options That Affect Package Behavior" of tikzDevice-package.

verbose

A logical value indicating whether diagnostic messages are printed when measuring dimensions of strings. Defaults to TRUE in interactive mode only, to FALSE otherwise.

diagnose

pass TRUE to print detailed error information.

charCode

an integer that corresponds to a symbol in the ASCII character table under the Type 1 font encoding. All numeric values are coerced using as.integer(). Non-numeric values will not be accepted.

Details

These functions are used internally by the tikz device for proper string placement in graphics. Both functions check to see if metrics exist in a global or temporary dictionary (as defined in options('tikzMetricsDictionary')) and if so will pull the metrics from there. If the dictionary does not exist, then a temporary one is created for the current R session. Metrics are calculated via system calls to LaTeX compilers. Querying compilers to calculate metrics is expensive and so we strongly recommend setting options('tikzMetricsDictionary') <- '/path/to/dictionary' to create a global dictionary.

Value

getLatexStrWidth

The width of texString in points.

getLatexCharMetrics

A numeric vector holding ascent, descent and width. Values should all be nonnegative.

Author(s)

Charlie Sharpsteen source@sharpsteen.net and Cameron Bracken cameron.bracken@gmail.com

References

PGF Manual

Examples


   getLatexStrWidth('{\\\\tiny Hello \\\\LaTeX!}')


  # Calculate ascent, descent and width for "A"
  getLatexCharMetrics(65)


tikzDevice documentation built on May 29, 2024, 4:18 a.m.