Learn R Programming

FunWithNumbers (version 1.1)

cf2latex: Generate readable equations from the output of cfrac

Description

This function takes a vector of integers representing the values in a continued fraction and generates readable equations in two forms: inline as a character string, and LaTeX code.

Usage

cf2latex(vals, ...)

Value

eqn

The continued fraction as an inline equation

texeqn

LaTeX source code for presenting the continued fraction

texexpr

Markdown-ish string for use in plotting, typically like text(x,y,TeX(texexpr))

...

Arguments

vals

A vector of integers (or bigz, mpfr integer values)

...

Reserved for future upgrades

Author

Carl Witthoft, carl@witthoft.com

See Also

cfrac to generate continued fractions.

Examples

Run this code
355/113 - pi
# small number
 foo <- cfrac(355,113)
#[1]  3  7 16
 bar <- cf2latex(foo)
# $eqn
# [1] "3 + 1/(7 + 1/16)"
# $texeqn  #Paste into your LaTeX source file
# [1] "3 + \frac{1}{7 + \frac{1}{16}}"
# $texexpr  # use in an R plot window
# [1] "$3 + \frac{1}{7 + \frac{1}{16}}$"
##not run
# library( latex2exp)
# plot(NA,NA,xlim = c(1,10),ylim=c(1,5),axes=FALSE,xlab='',ylab='')
# text(2,4,TeX(bar$texexpr))

Run the code above in your browser using DataLab