Hello all,
last revision, now it works with non ruled functions see example above and the function name is written with small letters.
XRT program:
Code:
%%HP: T(3)A(R)F(,);
\<<
DO { 'XROOT(&A;&B)' 'XROT(&A;&B)' } \|^MATCH
UNTIL
END
\>>
the ->K code:
Code:
%%HP: T(3)A(R)F(,);
\<< \-> INTKL
\<< INTKL
\>>
\>>
the LOOKUP program:
Code:
%%HP: T(3)A(R)F(,);
\<< TXPAT SIZE 1, + \-> SGN NU
\<< 0,
DO
DROP 'NU' DECR
UNTIL
IF 0, ==
THEN 0, 1,
ELSE TXPAT NU GET
DUP HEAD SGN ==
END
END
\>>
\>>
the rulelist TXPAT:
Code:
%%HP: T(3)A(R)F(,);
{ { "+" "" "+" "" } { "-" "" "-" "" } { "*" "" "\\cdot " "" }
{ "/" "\\frac{" "}{" "}" } { "\->K" "\\left(" "\\right)" }
{ "\.S" "\\int_{" "}^{" "}" "d" "" } { "\v/" "\\sqrt{" "}" }
{ "XROT" "\\sqrt[" "]{" "}" } { "^" "{" "}^{" "}" } [
{"π" "\\pi "} {"e" "e"} {"i" "i"} }
and the main program:
Code:
%%HP: T(3)A(R)F(,);
\<< OBJ\-> @@Destruct object
IF OVER
THEN \-> N F @@Store fname
@@and number of arguments
\<< F N 1, + ROLLD @@store fname before arguments
@@on stack
1, N FOR J
IF DUP TYPE 9, == @@loop for analysing
@@every argument
THEN \->HP2TX @@if algebraic object
@@recursiv calling of
@@\->HP2TX
END
DUP @@argument or last
@@output of \->HP2TX
IF TYPE DUP @@local or global
@@name, if true
6, == SWAP
7, == OR
THEN \->STR DUP @@convert to a string
SIZE 1, - 2, @@and remove algebraic
SWAP SUB @@signs
ELSE \->STR @@numbers becomes
END @@a string
N ROLLD @@Roll down next
NEXT @@argument
N 1, + ROLL DUP @@self defined functions
IF TYPE DUP @@are from type
6, == SWAP @@local or global
7, == OR @@name
THEN \->STR DUP @@so they need
SIZE 1, - 2, @@same procedure
SWAP SUB @@like above
ELSE \->STR
END
DUP LOOKUP DUP
IF TYPE 5, ==
THEN
\-> RULE @@at that position
@@stack line 1
@@is the fname as
@@a string
@@lookup is a program
@@which searches in
@@the global variable
@@texpat for a translation-
@@pattern from RPL to
@@TeX
@@the rule found is
@@stored in the local
@@RULE
\<< DROP
RULE TAIL @@the first entry of RULE
@@is the RPL fname, no need
@@any more
'RULE' STO
RULE HEAD @@next entry is the beginning
@@of the TeX command
1, N FOR J @@loop for alternating compo-
RULE TAIL @@sition of argument and
'RULE' STO @@syntax of TeX command
N J - 2, + ROLL
+ RULE HEAD +
NEXT
\>>
ELSE DROP \-> FLN @@no rule found
\<< "\\text {" @@begin with simple function
1, FLN SIZE START @@caps transfered to small
@@ones
FLN HEAD NUM DUPDUP
IF 65, \>= SWAP 90, \<= AND
THEN 32, +
END
CHR +
FLN TAIL 'FLN' STO
NEXT
"}\\left(" + @@set end of functionname
SWAP + @@insert argument in between
"\\right)" + @@close argumentplace
\>>
END
\>>
ELSE
SWAP DROP
\->STR LOOKUP
TAIL HEAD
END
DUP 'OUT' STO @@display result as string and store
\>> @@and store it in global OUT
And now a example:
input: '\.S(1;2;XROT(SIN(5);\->K(A+B)^3);B)'
and you get:
\[
\int\limits_{1}^{2}\sqrt[\text{sin}\left(5\right)]{{\left(A+B\right)}^{3}}dB
\]
So have fun, maybe someone extends the rulelist and shares it with us.
greetings peaceglue
P.S.: EDIT: IMPORTANT!!!!!! e, pi, i are not typed as global variables, they are typed as algebraic expressions with no argument or operants, so wie have to do a little workaround. There is a little change in the main program ->HP2TEX and the TXPAT. The function names are also inserted with a command, that they aren't displayed in italics.