wdEqn: Write formulas in Word

Description Usage Arguments Details Value Examples

Description

This function allows writing formulas/equations into Word using the default formula editor in Word 2007 and 2010.

Usage

1
wdEqn(eqtext, bookmark = NULL, iknow=FALSE,waitsec=2,wdapp = .R2wd, paragraph = TRUE)

Arguments

eqtext

a text string containing the formula

bookmark

a text string containing the bookmark to use (otherwise default)

iknow

acknowledgement of danger using sendkeys

waitsec

time R waits while sendkey sends the equation

wdapp

the handle to the Word application

paragraph

whether to insert a paragraph after the equation

Details

This function uses two tools to write a formula to Word. At first it uses the COM client to write a text into the range property of the selection and converts it to a formula. Then it uses the sendkeys method of the wsshell to add a carriage return. This causes Word to parse the formula and to substitute LaTeX like tokens such as \alpha by their corresponding formula equivalents (the greek letter alpha). In principle, it should be possible to achieve the parsing of the formula by invoking the BuildUp method of the omaths(1) object, but this does not work in the current versions of Word. The route via Sendkeys is fragile, so handle with caution.

Value

none

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
wdGet()
wdTitle("Try a formula")
## note that double \ has to be used instead of \
## note that the , the following lines
## must be pasted into the console and run there.
## running them from an Emacs/ESS buffer won't work
wdEqn("\\alpha \\over ( \\beta +3 ) ")
wdEqn("\\alpha \\over (( \\beta +3 ))")
wdEqn("\\matrix(\\alpha &0@0&1 ) ")
## note: the handling of parentheses "(" is a bit peculiar in Word
## also experiment with the handling of empty spaces

## End(Not run)

R2wd documentation built on May 2, 2019, 8:54 a.m.