-
-
19 Mar 1998 07:12:00 UTC
- Distribution: etext
- Module version: 0.01
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues
- Testers
- Kwalitee
Bus factor: 1- License: unknown
- Activity
24 month- Tools
- Download (368.11KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
++ed by:1 non-PAUSE user- Dependencies
- unknown
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Text::TeX -- Perl module for parsing of
TeX
.SYNOPSIS
use Text::TeX; sub report { my($eaten,$txt) = (shift,shift); print "Comment: `", $eaten->[1], "'\n" if defined $eaten->[1]; print "@{$txt->{waitfors}} ", ref $eaten, ": `", $eaten->[0], "'"; if (defined $eaten->[3]) { my @arr = @{ $eaten->[3] }; foreach (@arr) { print " ", $_->print; } } print "\n"; } my $file = new Text::TeX::OpenFile 'test.tex', 'defaultact' => \&report; $file->process;
DESCRIPTION
A new
TeX
parser is created by$file = new Text::TeX::OpenFile $filename, attr1 => $val1, ...;
$filename may be
undef
, in this case the text to parse may be specified in the attributestring
.Recognized attributes are:
string
-
contains the text to parse before parsing $filename.
defaultact
-
denotes a procedure to submit
output tokens
to. tokens
-
gives a hash of
descriptors
forinput token
. A sane default is provided.
A call to the method
process
launches the parser.Tokenizer
When the parser is running, it processes input stream by splitting it into
input tokens
using some heuristics similar to the actual rules of TeX tokenizer. However, since it does not use the exact rules, the resulting tokens may be wrong if some advanced TeX command are used, say, the character classes are changed.This should not be of any concern if the stream in question is a "user" file, but is important for "packages".
Digester
The processed
input tokens
are handled to the digester, which handles them according to the providedtokens
attribute. A sequence ofinput tokens
is converted intooutput tokens
. To eachinput token
there corresponds 0 or moreoutput tokens
. Theoutput tokens
are delivered one-by-one to theaction
handler of the processor.Output token
is a reference to an object (which is usually an array reference). Some elements of the array have a special meaning to the Digester. The first one is the substring of the input which generated thistoken
. The second contains comment which preceeded this substring, orundef
.tokens
attributeThis is a hash reference which describes how the
input tokens
should be handled. A key to this hash is a literal like^
or\fraction
. A value should be another hash reference, with the following keys recognized:- class
-
Into which class to bless the token. Several predefined classes are provided. The default is
Text::TeX::Token
. - PostProcess
-
What kind of special processing to do with the input after the
class
methods are called. RecognizedPostProcess
s are:- delimit_args
-
When the token of this
PostProcess
is encountered, it is converted intoText::Tex::BegArgsToken
. Then the arguments are processed as usual, and anoutput token
of typeText::Tex::ArgToken
is inserted between them. Finally, after all the arguments are processed, anoutput token
Text::Tex::EndArgsToken
is inserted.The first element of these simulated
output tokens
is an array reference with the first element being the initialoutput token
which generated this sequence. The second element of the internal array is the number of arguments required by theinput token
. TheText::Tex::ArgToken
token has a third element, which is the ordinal of the argument which ends immediately before this token.If
lookahead
attribute is present, a tokenText::Tex::LookAhead
will be returned instead ofText::Tex::EndArgsToken
. The additional elements of$token-
[0]> are: the reference to the correspondinglookahead
attribute, the relevant key (text of following token) and the corresponding value.In such a case the input token which was looked-ahead would generate an output token of type
Text::Tex::BegArgsTokenLookedAhead
(if it usually generatesText::Tex::BegArgsToken
). - local
-
Used if this macro introduces a local change, which should be undone at the end of enclosing block. At the end of the block an output token
Text::TeX::EndLocal
is delivered, with$token-
[0]> being the output token which started the local event.Useful for font switching.
Some additional keys may be recognized by the code for the particular
class
.count
-
number of arguments to the macro.
waitfor
-
gives the matching token for a starting delimiter token.
eatargs
-
number of tokens to swallow literally and put into the relevant slot of the
output token
. The surrounding braces are stripped. selfmatch
-
is used with
eatargs==1
. Denotes that the matching token is alsoeatargs==1
, and the swallowed tokens should coinside (like with\begin{blah} ... \end{blah}
). lookahead
-
is a hash with keys being texts of tokens which need to be treated specially after the end of arguments for the current token. If the corresponding text follows the token indeed, a token
Text::Tex::LookAhead
is returned instead ofText::Tex::EndArgsToken
.
Symbol font table
The hash %Text::TeX::xfont contains the translation table from TeX tokens into the corresponding font elements. The values are array references of the form
[fontname, char]
, Currently the only font supported issymbol
.AUTHOR
Ilya Zakharevich, ilya@math.ohio-state.edu
SEE ALSO
perl(1).
Module Install Instructions
To install FreezeThaw, copy and paste the appropriate command in to your terminal.
cpanm FreezeThaw
perl -MCPAN -e shell install FreezeThaw
For more information on module installation, please visit the detailed CPAN module installation guide.