Tex Var Manual
User Manual:
Open the PDF directly: View PDF
.
Page Count: 24
| Download | |
| Open PDF In Browser | View PDF |
TexVar – Manual
TexVar – LaTeX math calculations
Version: 1.5.22
Sebastian Pech
November 27, 2018
Contents
1 Description
2
2 Installation
2.1 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2.1 Configuration for Gnuplot . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2
2
2
3 Getting Started - Hello World
2
4 General Information on tVar Environment and Macro
3
5 TexVar - Commands
5.1 Creating Variables . . . . . . . . . . . . . . . . . . .
5.1.1 Creating Variables in Equations . . . . . . . .
5.1.2 Auto-Formatting of variable names . . . . . .
5.2 Creating Functions . . . . . . . . . . . . . . . . . . .
5.3 Indexing Matrices and Vectors . . . . . . . . . . . .
5.4 Output . . . . . . . . . . . . . . . . . . . . . . . . .
5.4.1 print() . . . . . . . . . . . . . . . . . . . . . .
5.4.2 outRES() . . . . . . . . . . . . . . . . . . . .
5.4.3 Other Output Commands . . . . . . . . . . .
5.4.4 LATEX Output . . . . . . . . . . . . . . . . . .
5.4.5 Precise Manipulation of Output . . . . . . . .
5.4.6 Number Format . . . . . . . . . . . . . . . .
5.4.7 Grouping Math Environments . . . . . . . . .
5.5 Global Parameters . . . . . . . . . . . . . . . . . . .
5.5.1 Details on automatic removal of trailing zeros
5.6 Plotting with Gnuplot . . . . . . . . . . . . . . . . .
5.6.1 Configuration . . . . . . . . . . . . . . . . . .
5.6.2 Creating a Plot . . . . . . . . . . . . . . . . .
5.7 Mathematical Commands . . . . . . . . . . . . . . .
5.7.1 General . . . . . . . . . . . . . . . . . . . . .
5.7.2 Matrices and Vectors . . . . . . . . . . . . . .
5.8 The Link Function . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4
4
5
5
6
6
8
8
9
9
10
10
11
13
13
14
15
15
16
18
18
18
18
6 Examples
6.1 U-Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.2 Rotating a Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
20
21
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2
3 Getting Started - Hello World
6.3
Vector Calculations - Custom Function . . . . . . . . . . . . . . . . . . . . . . . .
22
1 Description
TexVar (short tVar) is a basic LATEX math calculations tool written in Lua. For integration into
LATEX it has to be used together with LuaLaTeX. Compared to software like Mathcad TexVar is
a lot more flexible. You can fill custom designed tables with results, do calculations within text
documents and print beautiful LaTeX equations. The current version also supports 2D-plotting
with gnuplot.
2 Installation
2.1 Prerequisites
The following software is needed in order to use TexVar:
• Lua 5.1 or higher
• LuaLaTeX (MikTex or Texlive)
• GnuPlot 5.0 (only needed for plotting)
By default the command \si{} is used for displaying units, so the siunitx package is mandatory.
If you want to define your own command you can change the value of tVar.unitCommand = "\\si".
2.2 Installation
Download TexVar from https://gitlab.com/spech/TexVar and copy the folder tVar and the
file texvar.sty (subfolder package) to a location that is visible to LATEX. (e.g. the folder your
*.tex file is in or a global LATEX-folder 1 )
2.2.1 Configuration for Gnuplot
In order to use Gnuplot with TexVar you have to allow LuaLaTeX to call external commands
during runtime. This works through the command-line switch --shell-escape. Your complete
call for LuaLaTeX could look like this: lualatex -synctex=1 -interaction=nonstopmode
--shell-escape %.tex.
3 Getting Started - Hello World
To ensure your installation is working test the following code. When using an luacode based
environment like tVar it’s important that the commands \begin{tVar} \end{tVar} are not
indented.
1
2
3
4
5
1
\ documentclass { article }
%
\ usepackage { texvar }
\ usepackage [ fleqn ]{ amsmath }
%
You can find information on global LATEX-folders athttps://www.math.hmc.edu/computing/support/tex/
installing/
4 General Information on tVar Environment and Macro
6
7
8
9
10
11
3
\begin { document }
\begin {tVar}
#Hello World ! I'm using TexVar
tVar.getVersion ()
\end{tVar}
\end{ document }
Hello World! I’m using TexVar Version: 1.5.22
Output
4 General Information on tVar Environment and Macro
To execute TexVar commands from LATEX, the TexVar package offers two options:
• \begin{tVar} \end{tVar}, for commands blocks
• \tv{}, for inline calls
Both forward the commands to the TexVar interpreter.
1 \begin {tVar}
2
a:=10
3
b:=3
4
c:=a+b
5 \end{tVar}
6 The result is: \tv{c: outRES ()}
Output
a = 10
b=3
c = a + b = 10 + 3 = 13
The result is: c = 13
Generally, there are two key commands the TexVar interpreter searches for 2 :
1. #, for text output
2. :=, for calculations and assignments
Every other command is directly forwarded to the Lua interpreter. This means you can write
any Lua code you want inside the tVar environment.
1 \begin {tVar}
2
function mypow (a,b)
3
return a^b
2
Details on these key commands are discussed in Section 5
4
5 TexVar - Commands
4
end
5
for i=0 ,2 do
6
tex.print ("Step " .. mypow (2,i) .. "\\\\")
7
end
8 \end{tVar}
Output
Step 1
Step 2
Step 4
5 TexVar - Commands
5.1 Creating Variables
TexVar knows three types of variables:
tVar
is the basic type for scalar values.
tMat is used for matrices.
tVec is used for vectors.
The following code generates a variable of each type. Every assignment is made with :=.
1 \begin {tVar}
2
a:=13
3
e:={1 ,2 ,4}
4
A:={{1 ,0} ,{2 ,4} ,{3 ,9 .1 }}
5 \end{tVar}
Output
a = 13
1
~e = 2
4
1 0
A = 2 4
3 9.1
5 TexVar - Commands
5
5.1.1 Creating Variables in Equations
New variables can also be created inside equations. The notation for vectors and matrices is
explained in Section 5.1. Lua knows - by default - how to do calculations with numbers, so
any equation which does not contain tVar objects, can only be printed as it’s result. Any
mathematical operation with a tVar object and a decimal number results in a tVar value.
1 \begin {tVar}
2
# Variable a is created from the equation ...
3
a :=13*2^2
4
# To preserver the equation some of the ...
5
a:= tVar:New (13) *2^2
6
# At first Lua calculates $2 ^2=4$ ...
7
# To print the whole ...
8
a:=13* tVar:New (2) ^2
9
# Matrices and Vectors
10
c:={{1 ,2 ,3} ,{4 ,2 ,6} ,{1 ,3 ,2}}*{1 ,2 ,3}*a
11 \end{tVar}
Output
Variable a is created from the equation 13 ·
Since all numbers are
just decimal values, Lua calculates the result and creates the tVar object
afterwards.
22 .
a = 52
To preserver the equation some of the numbers have to be initialized as
tVar objects. In this case it’s the number 13.
a = 13 · 4 = 52
At first Lua calculates 22 = 4 and then multiplies the tVar object 13 with
4 which results in a tVar object containing the equation. To print the
whole equation, one number from the first calculation has to be transformed into a tVar object.
a = 13 · 22 = 52
Matrices and
1
~c = 4
1
Vectors
2 3
1
1 2 3
1
728
2 6 · 2 · a = 4 2 6 · 2 · 52 = 1352
3 2
3
1 3 2
3
676
5.1.2 Auto-Formatting of variable names
The LATEX-representation of a variable is automatically generated from the variable name. The
first occurrence of an underline starts the subscript the first occurrence of a double underline
starts the superscript. Every other underline becomes a comma.
6
5 TexVar - Commands
1 \begin {tVar}
2
a_1_3 :=13
3
a__10_2 :=3
4
b_1_x__y_2 :=12
5 \end{tVar}
Output
a1,3 = 13
a10
2 =3
by,2
1,x = 12
5.2 Creating Functions
Functions can easily be defined with the following syntax. The auto-formatting of function
names and attribute names works according to Section 5.1.2.
1 \begin {tVar}
2
f(x,y):=x^2+y^2+4
3
a:=f(2 ,3) +11
4 \end{tVar}
Output
f (x, y) = x2 + y 2 + 4
a = f (2, 3) + 11 = 22 + 32 + 4 + 11 = 28
5.3 Indexing Matrices and Vectors
The syntax for indexing a matrix is similar to the Matlab syntax. To access a matrix you have to
use square brackets and a string as key. The key has to be formatted according to the following
examples.
1 \begin {tVar}
2
A:={{1 ,2 ,6} ,{2 ,4 ,6} ,{7 ,6 ,9}}
3
# Index one element with syntax [row , column ]
4
A["1,2"]: outRES ()
5
# Index a range
6
A["1:2 ,1: end"]: outRES ()
7
# The range 1: end is equal to :
8
A["1:2 ,:"]: outRES ()
5 TexVar - Commands
7
9
# You can also set matrices this way
10
A["1:2 ,:"]:={{1 ,2 ,3} ,{4 ,5 ,6}}
11
A["1:2 ,:"]: outRES ()
12
# Adress vector
13
c:=A[":,2"]
14
d:=A["2,:"]
15
# The above also applies to vectors
16
{plain
17
v_1 :={1 ,4 ,3}
18
#,~
19
v_1["2"]: outRES ()
20
#,~
21
v_1["1"]:=9
22
v_1: outRES ()
23
}
24 \end{tVar}
Output
1 2 6
A = 2 4 6
7 6 9
Index one element with syntax [row,column]
A[1,2] = 2
Index a range
A[1:2,1:end] =
1 2 6
2 4 6
!
The range 1:end is equal to :
!
1 2 6
A[1:2,:] =
2 4 6
You can also set matrices this way
!
1 2 3
A[1:2,:] =
4 5 6
Adress vector
2
2
~c = 5 = 5
6
6
8
5 TexVar - Commands
d~ = 4 5 6 = 4 5 6
The above also applies to vectors
1
9
~v1 = 4 , ~v1 [1] = 9, ~v1 = 4
3
3
The command {plain } groups equations to one math environment. For details see Section
5.4.7
5.4 Output
5.4.1 print()
The [tVar]:print() command creates the output according to the global parameter tVar.OUTPUT_MODE
. The following options are supported:
Output
a = 10
b=2
c = a + b = 10 + 2 = 12
tVar.OUTPUT_MODE = "RES_EQ_N"
c = a + b = 10 + 2 = 12
tVar.OUTPUT_MODE = "RES_EQ"
c = a + b = 12
tVar.OUTPUT_MODE = "RES"
c = 12
If you do your calculations inside \begin{tVar} and \end{tVar} the [tVar]:print() command
is automatically added to your calculations. This means c:=(a+b) creates an output using the
[tVar]:print() command. To suppress the automatic output just add a ”;” at the end of the
line.
1 \begin {tVar}
2
# With output :
3
a:=10
4
b:=3
5
c:=a+b
6
# Without output ( Lines 7 and 8 produce no output ):
5 TexVar - Commands
9
7
a:=10;
8
b:=3;
9
c:=a+b
10 \end{tVar}
With output:
Output
a = 10
b=3
c = a + b = 10 + 3 = 13
Without output (Lines 7 and 8 produce no output):
c = a + b = 10 + 3 = 13
5.4.2 outRES()
The [tVar]:outRES() command is equal to the combination of [tVar]:print() with tVar.OUTPUT
\_MODE = "RES". If you do your calculations inside \begin{tVar} and \end{tVar} the [tVar
]:outRES() command is automatically added to any assignment of a new variable. That means
a:=10 creates and output using the [tVar]:outRES() command.
In some cases you might want to print an equation without assigning it to a variable. This
can be achieved by directly calling the function tVar.outRES([tVar]) (now with a dot) and
passing your equation as argument to the function.
1 \begin {tVar}
2
a:=2
3
b:=13
4
tVar.outRES ((a+b)/2+b)
5 \end{tVar}
Output
a=2
b = 13
a+b
+ b = 20.5
2
This method also works for the output commands listed in Section 5.4.3.
5.4.3 Other Output Commands
For every output mode mentioned in Section 5.4.1 there is an equal output function.
10
5 TexVar - Commands
RES_EQ_N [tVar]:outRES_EQ_N(numbering,environment)
RES_EQ
[tVar]:outRES_EQ(numbering,environment)
RES
[tVar]:outRES(numbering,environment)
The attributes numbering and environment are boolean values and define if the output is created
with numeration and a math environment. Both parameters are optional and can also be defined
via the global parameters tVar.EQUATION_NUMBERING and tVar.MATH_ENVIRONMENT3
Additionally there are the functions [tVar]:out() for printing the result without the variable
name and [tVar]:outN() for printing the variable name the equation with numbers and the
result.
5.4.4 LATEX Output
Inside \begin{tVar} and \end{tVar} the symbol # can be used to print a text in LATEX.
Inside such a text you can use %%[tVar]%% to print a variables name and $$[tVar]$$ to print
a variables value.
LATEX commands used within # have to be escaped. For example \textbf{} has to be written
as \\textbf{}.
1 \begin {tVar}
2
#\\ subsection *{ First Subsection }
3
a_1_2 :=22 .4: setUnit ("m")
4
# Linebreaks are a bit confusing \\\\
5
# The variable %% a_1_2 %% has the value $$a_1_2$$
6 \end{tVar}
Output
First Subsection
a1,2 = 22.4 m
Linebreaks are a bit confusing
The variable a1,2 has the value 22.4 m
5.4.5 Precise Manipulation of Output
The following functions manipulate equations directly and can be used for detailed formatting.
1 \begin {tVar}
2
a:=10: setUnit ("m")
3
b:=3: setUnit ("m")
4
c :=(((( a+b): bracR () ^2): bracB () *5): bracC () *22): setUnit ("m^2")
5
#In case you do a really long calculation you can insert a
linebreak \\\\
3
In case tVar.MATH_ENVIRONMENT is set to ”” no math environment is used.
5 TexVar - Commands
11
6
c:=((a+a+a+a+a+a+a+a+b+b):CRLF("+")+b+b+b: CRLF_EQ ("+")+b+b+b+
a+a+a+a): CRLFb ("=")
7
tVar.DEBUG_MODE = "off"
8 \end{tVar}
Output
a = 10 m
b=3m
c=
nh
i o
nh
i o
(a + b)2 · 5 · 22 = (10 + 3)2 · 5 · 22 = 18590 m2
In case you do a really long calculation you can insert a linebreak
c = a + a + a + a + a + a + a + a + b + b + b + b + b+
+b+b+b+a+a+a+a=
= 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 3 + 3+
+ 3 + 3 + 3 + 3 + 3 + 3 + 10 + 10 + 10 + 10 = 144
5.4.6 Number Format
The number format can be controlled globally and locally. The function [tVar]:setFormat([
string]) defines the local number format of a tVar object. In case no local format was defined,
tVar falls back to the global format set with tVar.NUMBERFORMAT = [string].
Common values are:
Variable a is set to 192.6345
Integer %d
Output
a = 192
Exponential %.2E
a = 1.93 · 102
Float %.3f
a = 192.635
There is one case where TexVar automatically changes the number format: When the output
precision return 0 but the calculation precision is unequal to 0 the number format is changed to
%.3E.
12
5 TexVar - Commands
[tVar]:bracR()
[tVar]:bracB()
[tVar]:bracC()
Surrounds the [tVar] object with round brackets.
… boxed brackets.
… curly brackets.
[tVar]:bracR_EQ()
Surrounds the equation part of the [tVar] object
with round brackets.
… boxed brackets.
… curly brackets.
[tVar]:bracB_EQ()
[tVar]:bracC_EQ()
[tVar]:bracR_N()
[tVar]:bracB_N()
[tVar]:bracC_N()
[tVar]:CRLF ([string])
[tVar]:CRLFb([string])
[tVar]:CRLF_EQ ([string])
[tVar]:CRLFb_EQ([string])
[tVar]:clean()
[tVar]:setUnit([string])
[tVar]:setFormat([string])
Surrounds the numerical part of the [tVar] object with round brackets.
… boxed brackets.
… curly brackets.
Inserts a line break in N after the [tVar] object and adds the string before and after the line
break.
Inserts a line break in N before the [tVar] object and adds the string before and after the line
break.
Inserts a line break in EQ after the [tVar] object and adds the string before and after the line
break.
Inserts a line break in EQ before the [tVar] object and adds the string before and after the line
break.
Removes the calculation history from an object.
Sets the unit for a tVar object.
Sets the numberformat for a tVar Object. For
details see Section 5.4.6
Output
Variable a is set to 0.00001. Default number format is %.3f. Calculation
precision is 10
a = 1 · 10−5
b = 123432
c = a · b = 1 · 10−5 · 123432 = 1.234
5 TexVar - Commands
13
5.4.7 Grouping Math Environments
By default TexVar creates a new mathematical environment for every output (except plain textoutput with #). To group equations into one environment, you can enclose them with curly
brackets. The group operator automatically adds an alignment symbol at the beginning of the
line and a line-break at the end. If you want to suppress this behavior you can open the group
with the command {plain.
1 \begin {tVar}
2
{
3
a:=1
4
b:=10
5
c:=3
6
}
7
d:=(a+b): bracR ()/c
8
#It's also possible to create environments without line breaks and alignment :
9
{plain
10
f:=3
11
#,~
12
g:=f+d
13
}
14 \end{tVar}
Output
a=1
b = 10
c=3
d=
(a + b)
(1 + 10)
=
= 3.667
c
3
It’s also possible to create environments without line-breaks and alignment:
f = 3, g = f + d = 3 + 3.667 = 6.667
5.5 Global Parameters
Global parameters can be set during runtime and affect all commands.
14
5 TexVar - Commands
Tab. 1: Global parameters with default values and description
tVar.NUMBERFORMAT = "%.3f"
tVar.MATH_ENVIRONMENT = "align"
tVar.OUTPUT_MODE = "RES_EQ_N"
tVar.EQUATION_NUMBERING = true
tVar.DECIMAL_SEPARATOR = "."
tVar.MATRIX_COMMAND = "mathbf"
tVar.MATRIX_EQUATION_AS_MATRIX = false
tVar.UNIT_COMMAND = "\\si""
tVar.VECTOR_COMMAND = "vec"
tVar.CALC_PRECISION = 10
tVar.OUTPUT_DISABLED = false
tVar.REMOVE_ZEROS = true
tVar.REMOVE_DECIMAL_SEPARATOR = true
tVar.DEBUG_MODE = "off"
tVar.DEBUG_LOG_COMMANDS_TO_FILE = false
tVar.OUTPUT_COLORED = false
Defines the number format for printing.
Defines the environment used around equations.
Defines the outputmode (Section 5.4.1).
Disables and enables numeration of equations.
Defines the decimal separator.
Defines the style for matrices.
Enables and disables output of a matrix as variable name or matrix with variable names
Sets the macro for displaying units.
Defines the style for vectors.
Defines the how many decimal places are used
for comparison.
Disables the complete output.
Removes trailing zeros from a decimal number.
In case tVar.REMOVE_DECIMAL_SEPARATOR is
true remove the decimal separator if all trailing zeros have been removed. Else show number with one decimal zero. (Only works if
tVar.REMOVE_DECIMAL_SEPARATOR = true)
In case debugMode is set to ”on” the equations
are printed as LATEXcode.
Enables logging of interpreted commands. Creates a file tVarLog.log
Prints all variables with value=nil red.
5.5.1 Details on automatic removal of trailing zeros
The following example shows the difference between the global parameters tVar.REMOVE_DECIMAL_SEPARATOR
and tVar.REMOVE_ZEROS. If tVar.REMOVE_ZEROS is disabled the number format from tVar.NUMBERFORMAT
get’s applied.
1 \begin {tVar}
2
# Default settings
3
{
4
a:=2 .0
5
b:=3 .3
6
c:= tVar.sqrt (a^2+b^2)
7
}
8
# Disable \\ verb| tVar.REMOVE_DECIMAL_SEPARATOR |
9
tVar.REMOVE_DECIMAL_SEPARATOR = false
10
{
11
a:=2 .0
12
b:=3 .3
5 TexVar - Commands
15
13
c:= tVar.sqrt (a^2+b^2)
14
}
15
# Disable \\ verb| tVar.REMOVE_ZEROS |
16
tVar.REMOVE_ZEROS = false
17
{
18
a:=2 .0
19
b:=3 .3
20
c:= tVar.sqrt (a^2+b^2)
21
}
22 \end{tVar}
Default settings
Output
a=2
b = 3.3
p
p
c = a2 + b2 = 22 + 3.32 = 3.859
Disable tVar.REMOVE_DECIMAL_SEPARATOR
a = 2.0
b = 3.3
p
p
c = a2.0 + b2.0 = 2.02.0 + 3.32.0 = 3.859
Disable tVar.REMOVE_ZEROS
a = 2.000
b = 3.300
p
p
c = a2.000 + b2.000 = 2.0002.000 + 3.3002.000 = 3.859
5.6 Plotting with Gnuplot
Plotting in TexVar is support via Gnuplot. The code describing the figure is generated in TexVar
and is sent to Gnuplot which creates the graphics.
5.6.1 Configuration
For enabling plotting the path to the Gnuplot executable has to be set via a global parameter.
By default its set to tVar.GNUPLOT_LIBRARY ="gnuplot". In case you work on a windows
system and want to specify the absolute path to your Gnuplot install the command has to be
tVar.GNUPLOT_LIBRARY =[==["WINDOWSPATH"]==].
The Gnuplot terminal is by default tVar.GNUPLOT_TERMINAL = "postscript eps enhanced
color font 'Helvetica,12'" and the file extension is tVar.GNUPLOT_FILE_NAME_EXTENSION
= "eps".
16
5 TexVar - Commands
5.6.2 Creating a Plot
Every parameter set through [tPlot].* is directly translated to a gnuplot command. Actually
tPlot is only aware of the following commands
tPlot:New(present[tPlot])
[tPlot].steps = 0.1
[tPlot].conf.size = "14cm,8
cm"
[tPlot].xrange = "[0,10]"
[tPlot]:add(f or
{{1,2},{3,2}},"f(x)", "
with line lt 1 lc 2")
[tPlot]:plot()
Creates a new plot. Present is an optional parameter. If a value gets passed the configuration
of the plot is used as template for the new plot.
Resolution for functions
Size of the plot
Range of the x axis and min and max value for
function creation.
Adds a functions or points to the plot.
Generates the plot and returns the includegraphics command.
1 \begin {tVar}
2
f(x):=1/x
3
4
plot1 = tPlot :New ()
5
plot1.xlabel = "{/ Symbol e}_c"
6
plot1.ylabel = "{/ Symbol s}_c"
7
plot1.steps = 0.001
8
9
plot1.xtics = "0.1"
10
plot1.xrange = " [0:1] "
11
plot1.yrange = " [0:16] "
12
plot1.conf.size = "6cm ,6cm"
13
plot1 :add(f,"f(x)", "with line lt 1 lc 2")
14
plot1 :add ({{0.2 ,6} ,{0.5 ,12}} , "pt", "with points lc 1")
15
#\\ begin { center }
16
plot1 :plot ()
17
#\\ end{ center }
18 \end{tVar}
Output
f (x) =
1
x
5 TexVar - Commands
17
16
f(x)
pt
14
12
σc
10
8
6
4
2
0
0
0.2
0.4
0.6
0.8
1
εc
Currently TexVar only supports 2D plots and functions with one attribute. If you want to
print a function with more than one attribute you can create a helper function.
1 \begin {tVar}
2
-- use plot1 as template
3
plot2 = tPlot :New( plot1 )
4
5
f(x,z) :=(1/ x)^z
6
-- helper functions with fixed z values
7
f_h_1 (x):=f(x ,2);
8
f_h_2 (x):=f(x ,1);
9
10
plot2 :add(f_h_1 ,"z=2","with line lt 1 lc 2")
11
plot2 :add(f_h_2 ,"z=1","with line lt 1 lc 3")
12
13
#\\ begin { center }
14
plot2 :plot ()
15
#\\ end{ center }
16 \end{tVar}
Output
1z
x
16
z=2
z=1
14
12
10
σc
f (x, z) =
8
6
4
2
0
0
0.2
0.4
0.6
εc
0.8
1
18
5 TexVar - Commands
5.7 Mathematical Commands
The following subsections are just a listing of currently implemented mathematical functions.
5.7.1 General
These functions can be used with every tVar object.
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
tVar.sqrt([tVar],[tVar] nth -root)
tVar.PI
tVar.abs([tVar])
tVar.acos([tVar])
tVar.acosd([tVar])
tVar.cos([tVar])
tVar.cosd([tVar])
tVar.cosh([tVar])
tVar.asin([tVar])
tVar.asind([tVar])
tVar.sin([tVar])
tVar.sind([tVar])
tVar.sinh([tVar])
tVar.atan([tVar])
tVar.atand([tVar])
tVar.tan([tVar])
tVar.tand([tVar])
tVar.tanh([tVar])
tVar.ceil([tVar])
tVar.floor([tVar])
tVar.exp([tVar])
tVar.ln([tVar])
tVar.log10([tVar])
tVar.atan2(X[tVar],Y[tVar])
tVar.fact([tVar])
5.7.2 Matrices and Vectors
These functions can only be used with tMat or tVec objects.
•
•
•
•
[tMat]:T()
[tMat]:Det()
[tMat]:Inv()
tVec.crossP([tVec],[tVec])
5.8 The Link Function
If you want to use your own functions within TexVar, you can use the Link function to link
them to tVar functions. This only applies to functions that don’t use TexVar objects for calculation. If you want to write a TexVar function see Section 5.2. The following code shows the
implementation of the factorial function with the link function.
1 \begin {tVar}
2
function mycalcFactorial (n)
5 TexVar - Commands
19
3
-- no tVar objects here just numbers
4
if n <=1 then return 1 end
5
return n* mycalcFactorial (n -1)
6
end
7
8
-- link it
9
myfact = tVar.link ( mycalcFactorial ,"","!",nil ,nil ,nil ,true)
10
11
a:=10
12
b:= myfact (a)
13 \end{tVar}
Output
a = 10
b = a! = 10! = 3628800
The link function has the following attributes:
• function: The function that should be transformed to a TexVar function.
• texBefore: Text which is added before the return value.
• texAfter: Text which is added after the return value.
• returntype (optional): Defines the type of the return objecte, possible values are tVar,
tMat, tVec
• inputUnit (optional): Required unit for input attributes.
• outputUnit (optional): Unit of returned function.
• pipeUnit (optional): If true, the input and output unit is derived from the first passed
argument.
All Lua math functions are implemented this way.
For example the Lua function math.atan2:
1
2
3
4
5
6
--- calculates inverse tangens with with appr. quadrant
--- @param opposite (tVar , number ) values
-- @param adjacent (tVar , number ) values
-- @return (tVar)
tVar.link ( math.atan2 ,"\\ text{ atan2 }\\ left(","\\ right )",nil ,
tVar.units ("m"),tVar.units ("rad"),false)
20
6 Examples
Output
a=3m
b=4m
c = atan2 (a; b) = atan2 (3; 4) = 0.644
6 Examples
6.1 U-Value
This is a very simple example using only the basic functionality of TexVar.
1 Calculating the U- Value for an element with two layers. \\
2 \begin {tVar}
3
#\\ noindent Resistance of surface
4
{plain
5
R_se := 0.3: setUnit ("m^2 .K/W")
6
#,~
7
R_si := 0.13: setUnit ("m^2 .K/W")
8
}
9
# Parameters for elements
10
{
11
d_1 := 0.20: setUnit ("m")
12
\\ lambda_1 := 0.035: setUnit ("W/( m.K)")
13
d_2 := 0.10: setUnit ("m")
14
\\ lambda_2 := 0.5: setUnit ("W/( m.K)")
15
}
16
# Calculate thermal resistance
17
R := (R_se + d_1/ lambda_1 + d_2/ lambda_2 + R_si): setUnit ("m^2
.K/W")
18
# Calculate U- Value
19
U:=(1/ R): setUnit ("W/(m^2 .K)")
20 \end{tVar}
Calculating the U-Value for an element with two layers.
Resistance of surface
Rse = 0.3 m2 K/W, Rsi = 0.13 m2 K/W
Output
6 Examples
21
Parameters for elements
d1 = 0.2 m
λ1 = 0.035 W/(m K)
d2 = 0.1 m
λ2 = 0.5 W/(m K)
Calculate thermal resistance
R = Rse +
d1
d2
0.2
0.1
+
+ Rsi = 0.3 +
+
+ 0.13 = 6.344 m2 K/W
λ1 λ2
0.035 0.5
Calculate U-Value
U=
1
1
=
= 0.158 W/(m2 K)
R
6.344
6.2 Rotating a Vector
This example shows the usage of the parameter tMat.eqTexAsMatrix as mentioned in Section
5.5.
1
2
3
4
5
6
7
8
9
\begin {tVar}
tMat.MATRIX_EQUATION_AS_MATRIX = true
# Rotation angle in degree
\\ theta :=45: setUnit ("°")
# Rotation matrix in R2
{
A := {{ tVar.cos ( theta ),-tVar.sin ( theta )},{ tVar.sin ( theta ),
tVar.cos ( theta )}}: outRES_EQ ()
10 e_x :={1 ,0}
11 }
12
13
14 tMat.MATRIX_EQUATION_AS_MATRIX = false
15 e:=(A*e_x)
16 \end{tVar}
Rotation angle in degree
θ = 45 °
Output
22
6 Examples
Rotation matrix in R2
A=
~ex =
!
cos (θ) (−sin (θ))
=
sin (θ)
cos (θ)
!
1
0
~e = A · ~ex =
!
0.525 (−0.851)
0.851
0.525
!
0.525 (−0.851)
·
0.851
0.525
!
1
=
0
0.525
0.851
!
6.3 Vector Calculations - Custom Function
This example shows how to create a custom TexVar function for calculating the angle between
two vectors. The function has an extra parameter for disabling printing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\begin {tVar}
tVar.OUTPUT_MODE = " RES_EQ "
function angleBetweenVectors (a,b, disablePrinting )
if disablePrinting then
tVar.OUTPUT_DISABLED = true
end
# Calculate the length of the vectors
len_a := tVar.sqrt (a*a)
len_b := tVar.sqrt (b*b)
# Normalize the vectors
a_n :=(a/ len_a )
b_n :=(b/ len_b )
\\ alpha := tVar.acosd (a_n*b_n): setUnit ("°")
if disablePrinting then
tVar.OUTPUT_DISABLED = false
end
return alpha
end
#With output
{
v_1 :={1 ,0.4 ,0 .5}
v_2 :={0.3 ,1 ,0}
}
6 Examples
33
34
35
36
37
38
39
40
41
42
23
\\ alpha_1 := angleBetweenVectors (v_1 ,v_2)
# Without output
{
v_3 :={4 ,0.2 ,5}
v_4 :={9.3 ,8 ,1}
}
\\ alpha_2 := angleBetweenVectors (v_3 ,v_4 ,true)
\end{tVar}
With output
1
~v1 = 0.4
0.5
0.3
~v2 = 1
0
Calculate the length of the vectors
p
lena = ~v1 · ~v1 = 1.187
lenb =
p
~v2 · ~v2 = 1.044
Normalize the vectors
0.842
~v1
~an =
= 0.337
lena
0.421
0.287
~bn = ~v2 =
0.958
lenb
0
α = acos ~an · ~bn = 0.971 °
α1 = α = 0.971 °
Output
24
6 Examples
Without output
4
~v3 = 0.2
5
9.3
~v4 = 8
1
α2 = α = 0.982 °
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.5 Linearized : No Page Count : 24 Page Mode : UseOutlines Author : Title : Subject : Creator : LaTeX with hyperref package Producer : LuaTeX-1.7.0 Create Date : 2018:11:27 21:02:11+01:00 Modify Date : 2018:11:27 21:02:11+01:00 Trapped : False PTEX Full Banner : This is LuaTeX, Version 1.07.0 (TeX Live 2018)EXIF Metadata provided by EXIF.tools