/usr/share/perl5/LaTeXML/Package/multido.sty.ltxml is in latexml 0.8.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | # -*- CPERL -*-
# /=====================================================================\ #
# | multido.sty | #
# | Implementation for LaTeXML | #
# |=====================================================================| #
# | Part of LaTeXML: | #
# | Public domain software, produced as part of work done by the | #
# | United States Government & not subject to copyright in the US. | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov> #_# | #
# | http://dlmf.nist.gov/LaTeXML/ (o o) | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;
###########################################################################
##
###########################################################################
DefRegister('\multido@count' => Number(0));
DefRegister('\multidocount' => Number(0));
DefRegister('\multido@stuff' => Tokens());
DefMacro('\multido', '\multido@{}{\begingroup}{\endgroup}');
DefMacro('\mmultido', '\multido@{\multido@stepvar}{\begingroup}{\endgroup}');
DefMacro('\Multido', '\multido@{}{}{}');
DefMacro('\MMultido', '\multido@{\multido@stepvar}{}{}');
DefMacro('\multido@{}{}{}{}{}{}',
'#2'
. '\multido@count=#5\relax'
. '\ifnum\multido@count=\z@\else\multido@@{#1}{#4}{#6}\fi'
. '#3'
. '\ignorespaces');
# Simplified...
DefMacro('\multido@@{}{}{}',
'\multido@@initvars@@{#2}'
. '\ifnum\multido@count<\z@\multido@count=-\multido@count\fi'
. ' \multidocount=1\relax'
. '#1'
. '\multido@stuff{#3}'
. '\multido@loop');
DefMacro('\multido@loop',
'\the\multido@stuff'
. '\ifnum\multidocount<\multido@count'
. '\advance\multidocount\@ne'
. '\multido@stepvar'
. '\expandafter\multido@loop'
. '\fi');
DefMacro('\multidostop', '\multidocount=\multido@count');
# Annoyances with variables:
# Dimensions are always printed in scaled points (sp)
# Number are fixed point (and print that way!)
# concievably variables can be redefined in middle of loop?
DefMacro('\multido@@initvars@@{}', sub {
my ($ogullet, $variables) = @_;
$ogullet->readingFromMouth(LaTeXML::Core::Mouth->new(), sub {
my ($gullet) = @_;
$gullet->unread($variables);
my @inits = ();
my @steps = ();
while (my $var = $gullet->readToken) {
if ($var->getCSName =~ /^\\(d|n|i|r)/i) {
my $type = $1;
$gullet->readKeyword("=")
or Error('expected', '=', $gullet, "Missing = in multido variables");
my ($init, $step);
if ($type eq 'd') { $init = Tokens(Explode($gullet->readDimension->valueOf . "sp")); }
elsif ($type eq 'n') { $init = Tokens($gullet->readFloat->revert); }
elsif ($type eq 'i') { $init = Tokens($gullet->readNumber->revert); }
elsif ($type eq 'r') { $init = Tokens($gullet->readFloat->revert); }
push(@inits, T_CS('\def'), $var, T_BEGIN, $init, T_END);
$gullet->readKeyword("+")
or Error('expected', '+', $gullet, "Missing + in multido variables");
if ($type eq 'd') { $step = $gullet->readDimension; }
elsif ($type eq 'n') { $step = $gullet->readFloat; }
elsif ($type eq 'i') { $step = $gullet->readNumber; }
elsif ($type eq 'r') { $step = $gullet->readFloat; }
$step = $step->negate if LookupValue('\multido@count')->valueOf < 0;
push(@steps, T_CS('\multido@step@' . $type), $var, T_BEGIN, $step->revert, T_END);
last unless $gullet->readKeyword(","); }
else {
Error('unexpected', $var, $gullet,
"Wrong format for multido variable '" . ToString($var) . "'"); } }
DefMacroI('\multido@stepvar', undef, Tokens(@steps));
# Return the tokens to initialize the vars
@inits; }); });
DefMacro('\multido@step@d DefToken {Dimension}', sub {
my ($gullet, $v, $step) = @_;
my $value = Dimension(ToString(Expand($v)))->add($step);
DefMacroI($v, undef, Tokens(Explode($value->valueOf . 'sp'))); });
DefMacro('\multido@step@i DefToken {Number}', sub {
my ($gullet, $v, $step) = @_;
my $value = Number(ToString(Expand($v)))->add($step);
DefMacroI($v, undef, Tokens(Explode($value->valueOf))); });
DefMacro('\multido@step@r DefToken {Float}', sub {
my ($gullet, $v, $step) = @_;
my $value = Float(ToString(Expand($v)))->add($step);
DefMacroI($v, undef, Tokens(Explode($value->valueOf))); });
# Note: n _should_ be fixed point!
# DefMacro('\multido@step@n DefToken {Float}',sub {
# my($gullet,$v,$step)=@_;
# my $value = Float(ToString(Expand($v)))->add($step);
# DefMacroI($v,undef,Tokens(Explode($value->valueOf))); });
DefMacro('\multido@step@n DefToken {}', '\fpAdd{#1}{#2}{#1}');
# Should evolve these to work in fixed point (particularly, the formatting?)
DefMacro('\fpAdd {Float} {Float} DefToken', sub {
my ($gullet, $a, $b, $token) = @_;
my $value = $a->add($b);
DefMacroI($token, undef, Tokens(Explode($value->valueOf))); });
DefMacro('\fpSub {Float} {Float} DefToken', sub {
my ($gullet, $a, $b, $token) = @_;
my $value = $a->subtract($b);
DefMacroI($token, undef, Tokens(Explode($value->valueOf))); });
1;
|