mavscript - with BeanShell
Copyright (c) A.Vontobel, 2004 - 2016
With Mavscript you can do calculations in a text document.
The following file formats are supported:
- Text files
- OpenDocument Text odt (OpenOffice, LibreOffice)
- Hypertext html
- LaTeX tex (pdflatex, xelatex)
- other text based formats (i.e. svg). The
text file may be packed in a zip-archive.
Mavscript with BeanShell
Instead of a computer-algebra-system one may use BeanShell. BeanShell
is a scripting language for the programming language Java.
The basic mathematical operations are easily to use, but algebraic
functions are not available. BeanShell therefore is not a
replacement for a computer-algebra-program.
The power of BeanShell is that you can access external java
programs, that algorithms can be written in (simplified or
normal) Java and that the hole functionality of Java is
available. If you are a little bit familiar with the programming
language Java, you have got a very powerful tool.
How it works
Mavscript reads the calculation commands. These commands
start with the control characters §m and
end with one of the following control characters: §i, §o, §io and §n. Their meaning will be explained later. The
commands are forwarded to BeanShell. BeanShell evaluates them and
then returns an answer to Mavscript, i.e. the result of the
calculation command. Mavscript now can insert this answer in the
text, where the command was. When all calculations are done
Mavscript saves the text document in a new file out-originalname. The original file remains
unchanged.
You do not always want to replace
the calculation command by the answer from BeanShell. When you
assign a value to a variable you usually want that the command
remains in the text. Therefore there are the following
possibilities.
Input in the template file Output Notes
-------------------------- ------ -----
§m l = 5.0 §i l = 5.0 The command remains unchanged. §i stands for input.
§m b = 4.0 §i b = 3.0 The control characters are removed.
§m h = 2.0 §i m h = 2.0 m
§m V = l*b*h §io V = l*b*h --> 40. Both the input and the output are shown.
§m 2. + 3. * 4. §io 2. + 3. * 4. --> 14. §io stands for input/output.
§m doubleVol = 2*V §n Sometimes you do not want to show the command or its result.
§m static import Math.*; §n §n stands for nothing.
§m doubleVol §o 80. Only the return value (answer) is shown. §o stands for output.
§m sin(PI/4.) §o 0.7071067811865475 This is useful if you want to separate the calculation and
the results.
Some rules:
- A command must be placed in a single
line.
- Several commands may be in the same line.
Example: §m a=3. §i, §m
b=4. §i.
- In OpenOffice Writer the entire
command must be formatted the same way. Avoid double space
characters in commands.
- The syntax of the commands is the one of BeanShell or Java.
The manual is included in the directory path-to-mavscript/INFO/beanshell .
- Mavscript attaches a semicolon
(;) to each command. Therefore the
semicolon can be omitted in the commands.
- Caution when using third party templates
for mavscript-beanshell: The scripting functionality of
BeanShell is very powerful; the computer and its files can be
accessed. Have a look on the commands before calling mavscript
--beanshell.
Installation
see How to install
Usage
STANDARD
If Mavscript has been installed as described and the included
BeanShell is used:
- Create a template (input) file:
template.txt or
template.odt
- Drag the template file with the
mouse on the Mavscript-bsh-icon on the desktop.
- A window opens and the calculation is
executed. When finished, check if there is an error message and
close the window.
- Open the output file (out-template.txt or out-template.odt) .
ALTERNATE (in order to use advanced
functions or if the standard procedure does not work)
Mavscript alternately can be
called out of the shell (command prompt, konsole, terminal).
cd path-to-mavscript and then:
- mavscript-beanshell ./templatefile (Windows)
- ./mavscript-beanshell ./templatefile (Linux, Mac)
- java -jar mavscript*.jar --beanshell ./templatefile (all platforms)
ENHANCED FUNCTIONS
Tips
-
Mavscript expects commands to be on a single
line. But BeanShell is powerful because you can easily write
methods (algorithms, functions). If you have to write them on
a single line they are hardly readable.
This problem can be avoided if you save multi line commands
in a separate file (e.g. algorithm.bsh). The file then can be
called using one of the following ways:
- using the init option
mavscript --beanshell --init ./algorithm.bsh ./template.txt
- calling algorithm.bsh from the input file:
§m source("algorithm.bsh"); §n
The first way is useful for methods that are commonly
used. Have a look at the file lib/init.bsh, the methods
min(), max(), nf() are
defined there.
- The method
nf() (which is defined in the file
lib/init.bsh) is useful for formatting numbers.
mavscript --beanshell --init lib/init.bsh ./template.txt
Usage: §m nf(2.33333333, 2) §o returns
2.33
Disclaimer
- Use it at your own risk. Mavscript comes
with ABSOLUTELY NO WARRANTY.
- The program Mavscript is subject to the
free Licence GPL. It is included
in the file path-to-mavscript/INFO/LICENCE-GPL.txt . The licence allows the
usage of the program, but does impose clear rules if you intend
to distribute it. Mavscript is copyrighted by A.Vontobel.
- The included scripting engine
BeanShell is subject to the free licence LGPL. It is
included in the file path-to-mavscript/INFO/beanshell/LGPL .
The licence allows the usage of the program, but does impose clear rules
if you intend to distribute it.