diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/easylatex/easylatex |
Initial commit
Diffstat (limited to 'support/easylatex/easylatex')
26 files changed, 2927 insertions, 0 deletions
diff --git a/support/easylatex/easylatex/disabled/30autoAlignEquationsOutsideOfMathMode.pl b/support/easylatex/easylatex/disabled/30autoAlignEquationsOutsideOfMathMode.pl new file mode 100755 index 0000000000..b0fff3fa03 --- /dev/null +++ b/support/easylatex/easylatex/disabled/30autoAlignEquationsOutsideOfMathMode.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl -i + +use English; + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it + +my $notEqualsDoubleBackslashNotAmpersandRE = '(?:(?!\\\\\\\\)[^=&\n])*'; + +my $lineWithOneEqualsRE = $notEqualsDoubleBackslashNotAmpersandRE . '=' . $notEqualsDoubleBackslashNotAmpersandRE . '\n'; + +$file =~ s/(?:^|^\n|\n\n)($lineWithOneEqualsRE(?:$lineWithOneEqualsRE)+)(?:\n|$)/doBlock($1)/eg; + + + + + +print $file; + + +sub doBlock { + my ($block) = @_; + $block =~ s/=/&=&/g; + $block =~ s/(=.*\n)/$1\\\\/g; + $block = substr($block, 0,-2); # remove trailing \\ + $block = "\n\n".'\\begin{align*}' . "\n" . $block . '\\end{align*}' . "\n"; + return $block; +} + + + + + diff --git a/support/easylatex/easylatex/embed_transforms/25scriptedMatrix.pl b/support/easylatex/easylatex/embed_transforms/25scriptedMatrix.pl new file mode 100644 index 0000000000..adad4e80ec --- /dev/null +++ b/support/easylatex/easylatex/embed_transforms/25scriptedMatrix.pl @@ -0,0 +1,114 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR $file; + +## transform it + +my $openingSquareBracketsRE = '(?<!\\\\)\\[{3}'; +# in other words, we want '[[[', not preceded by a '\' + +my $closingSquareBracketsRE = '(?<!\\\\)\\]{3}'; + +my $not3ClosingSquareBracketsRE = '((?!\\]3).)*?'; + +$file =~ s/$openingSquareBracketsRE($not3ClosingSquareBracketsRE)$closingSquareBracketsRE/scriptedMatrixReplace($1)/egs; + +## print output +print $file; +#print "\n"; +#print STDERR $file; + + +###################### +# subroutines +###################### + +sub scriptedMatrixReplace { + my ($expr) = @_; + +# print STDERR "******** here: $expr\n"; + + my @rows; + my $out; + + @rows = createScriptedMatrix($expr); + $out = matrixToLatex(@rows); + + return $out; +} + +sub createScriptedMatrix { + my ($expr) = @_; + + $expr =~ /(\d+),(\d+),(.*)/s; + my $numRows = $1; + my $numCols = $2; + my $script = $3; + +# print STDERR "$numRows, $numCols, S: $script\n"; + + my @rows; + my $cols; + + for ($rowIndex = 0; $rowIndex < $numRows; $rowIndex++) { + $cols = []; + for ($colIndex = 0; $colIndex < $numCols; $colIndex++) { + local $i = $rowIndex + 1; + local $j = $colIndex + 1; + $cols->[$colIndex] = eval $script; +# print STDERR "On $i,$j\n"; + } + $rows[$rowIndex] = $cols; + } + +# use Data::Dumper; +# print STDERR Dumper(@rows); + + return @rows; +} + +sub matrixToLatex { + my @rows = @_; + + my @cols; + my ($row, $out); + my $colCount; + my $colSpecifier; + my $i; + my $out; + + foreach $row (@rows) { + @cols = @$row; + $colCount = $#cols + 1; + # yeah, okay, so we do this for every row + # and we only need to do it once! + foreach $col (@cols) { + $out .= "$col & "; + + } + $out = substr($out,0,-3); + ## STRIP OFF THE EXTRA & THAT WE PUT AFTER THE LAST COLUMN + $out .= "\n".'\\\\ '; + } + + ## STRIP OFF THE \\ THAT WE PUT AFTER THE LAST LINE OF THE MATRIX + $out = substr($out,0,-3); + + for ($i = 0; $i < $colCount; $i++) { + $colSpecifier .= 'l'; + } + + $out = '\left[ \begin{array}{'.$colSpecifier.'}'."\n".' ' . $out . '\end{array} \right]'; + +# print STDERR "**************$out\n"; + + return $out; +} + + diff --git a/support/easylatex/easylatex/math_mode_symbol_list.txt b/support/easylatex/easylatex/math_mode_symbol_list.txt new file mode 100644 index 0000000000..949c42962a --- /dev/null +++ b/support/easylatex/easylatex/math_mode_symbol_list.txt @@ -0,0 +1,612 @@ +\Arrowvert +\Bbbk +\Box +\Bumpeq +\Cap +\Cup +\Delta +\Diamond +\Doteq +\Downarrow +\Eins +\Finv +\Game +\Gamma +\Im +\Join +\LHD +\Lambda +\Langle +\Lbrack +\Leftarrow +\Leftrightarrow +\Lleftarrow +\Longleftarrow +\Longleftrightarrow +\Longrightarrow +\Lparen +\Lsh +\Omega +\P +\Phi +\Pi +\Psi +\RHD +\Rangle +\Rbrack +\Re +\Relbar +\Rightarrow +\Rparen +\Rrightarrow +\Rsh +\S +\Sigma +\Subset +\Supset +\Theta +\Uparrow +\Updownarrow +\Upsilon +\Vdash +\Vert +\Vvdash +\Xi +\acute +\aleph +\alpha +\amalg +\angle +\apprge +\apprle +\approx +\approxeq +\arrowaxisleft +\arrowaxisright +\arrowvert +\ast +\asymp +\axisshort +\backepsilon +\backprime +\backsim +\backsimeq +\backslash +\bar +\barwedge +\bbalpha +\bbbeta +\bbchi +\bbdelta +\bbespilon +\bbeta +\bbgamma +\bbiota +\bbkappa +\bblambda +\bbmu +\bbnu +\bbomega +\bbphi +\bbpi +\bbpsi +\bbrho +\bbsigma +\bbtau +\bbtheta +\bbupsilon +\bbxi +\bbzeta +\because +\beta +\beth +\between +\bigcap +\bigcirc +\bigcup +\bigodot +\bigoplus +\bigotimes +\bigsqcup +\bigstar +\bigtriangledown +\bigtriangleup +\biguplus +\bigvee +\bigwedge +\bitand +\blacklozenge +\blacksquare +\blacktriangle +\blacktriangledown +\blacktriangleleft +\blacktriangleright +\bot +\bowtie +\boxdot +\boxminus +\boxplus +\boxtimes +\braceld +\bracelu +\bracerd +\braceru +\bracevert +\breve +\bullet +\bumpeq +\cap +\capprod +\cdot +\cdotp +\cdots +\centerdot +\check +\chi +\circ +\circeq +\circlearrowleft +\circlearrowright +\circledS +\circledast +\circledcirc +\circleddash +\clubsuit +\colon +\comp +\complement +\cong +\coprod +\copyright +\cup +\cupprod +\curlyeqprec +\curlyeqsucc +\curlyvee +\curlywedge +\curvearrowleft +\curvearrowright +\dag +\dagger +\daleth +\dashdownarrow +\dashleftarrow +\dashrightarrow +\dashuparrow +\dashv +\ddag +\ddagger +\ddot +\ddots +\defineequal +\delta +\diagdown +\diagup +\diamond +\diamondsuit +\digamma +\div +\divideontimes +\dot +\doteq +\doteqdot +\dotplus +\dots +\doublebarwedge +\doublecap +\doublecup +\downarrow +\downdownarrows +\downharpoonleft +\downharpoonright +\ell +\emptyset +\epsilon +\eqcirc +\eqsim +\eqslantgtr +\eqslantless +\equiv +\eta +\eth +\exists +\fallingdotseq +\flat +\forall +\frown +\gamma +\ge +\geq +\geqq +\geqslant +\gets +\gg +\ggg +\gggtr +\gimel +\gnapprox +\gneq +\gneqq +\gnsim +\grave +\gtrapprox +\gtrdot +\gtreqless +\gtreqqless +\gtrless +\gtrsim +\gvertneqq +\hat +\hbar +\heartsuit +\hookleftarrow +\hookrightarrow +\hslash +\iff +\iiint +\iint +\image +\imath +\in +\infty +\int +\intercal +\intop +\invneg +\iota +\jmath +\kappa +\lVert +\lambda +\land +\langle +\lbrace +\lbrack +\lceil +\ldotp +\le +\leadsfrom +\leadsto +\leftarrow +\leftarrowtail +\leftharpoondown +\leftharpoonup +\leftleftarrows +\leftrightarrow +\leftrightarrows +\leftrightharpoons +\leftrightsquigarrow +\leftsquigarrow +\leftthreetimes +\leq +\leqq +\leqslant +\lessapprox +\lessdot +\lesseqgtr +\lesseqqgtr +\lessgtr +\lesssim +\lfloor +\lgroup +\lhd +\lhook +\ll +\llcorner +\lll +\llless +\lmoustache +\lnapprox +\lneq +\lneqq +\lnot +\lnsim +\logof +\longleftarrow +\longleftrightarrow +\longmapsto +\longrightarrow +\looparrowleft +\looparrowright +\lor +\lozenge +\lrcorner +\ltimes +\lvert +\lvertneqq +\mapsto +\mapstochar +\mathdollar +\mathparagraph +\mathsection +\mathsterling +\mathunderscore +\measuredangle +\mho +\mid +\midintop +\midointop +\midsurfintop +\models +\mp +\mu +\multimap +\nLeftarrow +\nLeftrightarrow +\nRightarrow +\nVDash +\nVdash +\nabla +\natural +\ncong +\ne +\nearrow +\neg +\neq +\nexists +\ngeq +\ngeqq +\ngeqslant +\ngtr +\ni +\nleftarrow +\nleftrightarrow +\nleq +\nleqq +\nleqslant +\nless +\nmid +\not +\notapprox +\notasymp +\notcong +\notequiv +\notin +\notni +\notsim +\notsimeq +\notsqsubseteq +\notsqsupseteq +\notsubset +\notsubseteq +\notsupset +\notsupseteq +\nparallel +\nprec +\npreceq +\nrightarrow +\nshortmid +\nshortparallel +\nsim +\nsubseteq +\nsubseteqq +\nsucc +\nsucceq +\nsupseteq +\nsupseteqq +\ntriangleleft +\ntrianglelefteq +\ntriangleright +\ntrianglerighteq +\nu +\nvDash +\nvdash +\nwarrow +\ocircle +\odot +\oiint +\oint +\ointop +\omega +\omicron +\ominus +\openclubsuit +\openspadesuit +\oplus +\original +\oslash +\otimes +\owns +\parallel +\partial +\period +\perp +\phi +\pi +\pitchfork +\pm +\pounds +\powersetsymbol +\prec +\precapprox +\preccurlyeq +\preceq +\precnapprox +\precneqq +\precnsim +\precsim +\prime +\prod +\propto +\psi +\rVert +\rangle +\rbrace +\rbrack +\rceil +\rfloor +\rgroup +\rhd +\rho +\rhook +\rightarrow +\rightarrowtail +\rightharpoondown +\rightharpoonup +\rightleftarrows +\rightleftharpoons +\rightrightarrows +\rightsquigarrow +\rightthreetimes +\risingdotseq +\rmoustache +\rtimes +\rvert +\searrow +\setdif +\setminus +\shadedclubsuit +\shadedspadesuit +\sharp +\shortmid +\shortparallel +\sigma +\sim +\simeq +\smallfrown +\smallint +\smallsetminus +\smallsmile +\smile +\spadesuit +\sphericalangle +\sqcap +\sqcup +\sqsubset +\sqsubseteq +\sqsupset +\sqsupseteq +\square +\star +\subset +\subseteq +\subseteqq +\subsetneq +\subsetneqq +\succ +\succapprox +\succcurlyeq +\succeq +\succnapprox +\succneqq +\succnsim +\succsim +\sum +\supset +\supseteq +\supseteqq +\supsetneq +\supsetneqq +\surd +\surfintop +\swarrow +\tau +\tccentigrade +\tcmu +\tcohm +\tcpertenthousand +\tcperthousand +\textregistered +\therefore +\theta +\thickapprox +\thicksim +\tilde +\times +\to +\top +\triangle +\triangledown +\triangleleft +\trianglelefteq +\triangleq +\triangleright +\trianglerighteq +\twoheadleftarrow +\twoheadrightarrow +\ulcorner +\unlhd +\unrhd +\upDelta +\upOmega +\upalpha +\uparrow +\upbeta +\upchi +\updelta +\updownarrow +\upepsilon +\upeta +\upgamma +\upharpoonleft +\upharpoonright +\upiota +\upkappa +\uplambda +\uplus +\upmu +\upnu +\upomega +\upphi +\uppi +\uppsi +\uprho +\upsigma +\upsilon +\uptau +\uptheta +\upuparrows +\upupsilon +\upvarepsilon +\upxi +\upzeta +\urcorner +\vDash +\varDelta +\varGamma +\varLambda +\varOmega +\varPhi +\varPi +\varPsi +\varSigma +\varTheta +\varUpsilon +\varXi +\varcirc +\varepsilon +\varint +\varkappa +\varnothing +\varoint +\varphi +\varpi +\varpropto +\varrho +\varsetminus +\varsigma +\varsubsetneq +\varsubsetneqq +\varsupsetneq +\varsupsetneqq +\vartheta +\vartriangle +\vartriangleleft +\vartriangleright +\vdash +\vdots +\vec +\vee +\veebar +\vert +\wasypropto +\wedge +\widehat +\widetilde +\wp +\wr +\xgeq +\xi +\xleq +\zeta +\ldots diff --git a/support/easylatex/easylatex/transforms/20escapeInsideGraphs.pl b/support/easylatex/easylatex/transforms/20escapeInsideGraphs.pl new file mode 100755 index 0000000000..775fe048c9 --- /dev/null +++ b/support/easylatex/easylatex/transforms/20escapeInsideGraphs.pl @@ -0,0 +1,118 @@ +#!/usr/bin/perl -i.bak.bak + +use English; + + + +use vars qw($EASYLATEXSTORE_RESERVED_WORD); +$EASYLATEXSTORE_RESERVED_WORD = 'EASYLATEXSTORE'; +use vars qw($StorageIndex @Stored); +$StorageIndex = 0; + + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR "********************** I got:\n\n" . $file . "\n"; + +## transform it + +$file =~ s/(\\begin{graph}.*?\\end{graph})/processGraph($1)/sge; + +# print output +print $file; + + +############### +# end of MAIN +############### + +sub processGraph { + my ($block) = @_; + + # to make it easier to put matrices in labels + $block =~ s/(\[\w+=[^"\]]+)(\[[^\]]+\])([^"\]]+\])/$1.store($2).$3/ge; +# $block =~ s/\[\w+=([^"\]]+)(\[[^\]]+\])/$1$2 HELLOOOOOOOOOOOOOOOOOOO/g; + + $block = storeMathModes($block); +#print STDERR "in 20esc:\n $block\n"; + + $block =~ s/\[label=((?!${EASYLATEXSTORE_RESERVED_WORD})[^,"\]]+)([,\]])/[label=\$$1\$$2/g; +# $block =~ s/\[label=([^"\]]+)\]/[label=\$$1\$]/g; +# $block =~ s/\[label=([^\]]+)\]/[label=\$$1\$]/g; +# $block =~ s/\[label=\$([^\]]+)(,[^\]=]*=[^\]]*)\$\]/[label=\$$1\$$2]/g; +# $block =~ s/\[label=\$([^\]]+)(,[^\]=]*=[^\]]*)\$\]/[label=\$$1\$$2]/g; + + +$block =~ s/=/\\=/g; +#$block =~ s/\[([^]]+=[^]]+)]/\\[$1\\]/g; + +$block =~ s/^(.*\S.*)(?<!;)(<!{)\n/$1;\n/mg; +$block =~ s/;//; # remove the ; we just added to "\begin{graph};" + +# default size limit, to keep graph from being bigger than the page +# + +if (! ($block =~ /size\\=/i)) +{$block =~ s/\\begin{graph}/\\begin{graph} size="6,10";/} + +$block = unstoreMathModes($block); + +# print STDERR "escapeInsideGraph: $block\n"; + + + + return $block; +} + + + + +###################### +# "store" subroutines +###################### + +sub storeMathModes { + my ($file) = @_; + + ${notSlashRE_begin} = '(^|(?!\\).)'; + ${notSlashRE} = '(?!\\).'; + + $file =~ s/(\\begin{align}.*?\\end{align})/store($1)/egs; + $file =~ s/(\\begin{align\*}.*?\\end{align\*})/store($1)/egs; + $file =~ s/(\\begin{eqnarray}.*?\\end{eqnarray})/store($1)/egs; + $file =~ s/(\\begin{eqnarray\*}.*?\\end{eqnarray\*})/store($1)/egs; + $file =~ s/(\\begin{equation}.*?\\end{equation})/store($1)/egs; + $file =~ s/(\\begin{equation\*}.*?\\end{equation\*})/store($1)/egs; + + $file =~ s/((?<!\\)\$.*?(?<!\\)\$)/store($1)/egs; + + return $file; +} + +sub unstoreMathModes { + my ($file) = @_; + +# print STDERR "UNSTORE:\n\n".$file; + + while ($file =~ s/${EASYLATEXSTORE_RESERVED_WORD}_(\d+)_${EASYLATEXSTORE_RESERVED_WORD}/$Stored{$1}/egs) {} + + return $file; +} + + + +sub store { + # got this idea from UseMod + my ($toBeStored) = @_; + + $Stored{$StorageIndex} = $toBeStored; +# print STDERR "STORED: $toBeStored\n"; + +# print STDERR "REPLACEDW: ".${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex . '_'.${EASYLATEXSTORE_RESERVED_WORD}; + + return ${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex++ . '_'.${EASYLATEXSTORE_RESERVED_WORD}; +} + diff --git a/support/easylatex/easylatex/transforms/25autoLinefeedInMathMode.pl b/support/easylatex/easylatex/transforms/25autoLinefeedInMathMode.pl new file mode 100644 index 0000000000..17d11c2fbd --- /dev/null +++ b/support/easylatex/easylatex/transforms/25autoLinefeedInMathMode.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it +my $alignOrEqnarrayRE = '(?:align|eqnarray)\\*?'; + +$file =~ s/(\\begin{($alignOrEqnarrayRE)}\n?)(.*?)(\\end{\2})/"$1".doBlock($3)."$4"/egs; + + +# print output +print $file; + + + +sub doBlock { + my ($block) = @_; + + my $notEqualsNotDoubleBackslashCharRE = '((?!\\\\\\\\).)*?'; + $block =~ s/(?<=\n)($notEqualsNotDoubleBackslashCharRE\n)/\\\\$1/gs; + + + return $block; +} + + + diff --git a/support/easylatex/easylatex/transforms/25wiki.pl b/support/easylatex/easylatex/transforms/25wiki.pl new file mode 100755 index 0000000000..e446faf536 --- /dev/null +++ b/support/easylatex/easylatex/transforms/25wiki.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR "*********** I got: $file\n"; + +## transform it + +$file =~ s/^:(.*)/\n\\ \\ \\ \\ \\ $1\n\\\\\n/gm; +$file =~ s/<pre>/\\begin{verbatim}/g; +$file =~ s/<\/pre>/\\end{verbatim}/g; +$file =~ s/-->/\\to/g; +#s/http:\/\/([\w\/\.]+)~([\w\/\.]*)/http:\/\/$1\\~{}$2/g; +$file =~ s/~/\\~{}/g; + +$file =~ s/\*\*([a-zA-Z][^\*]+)\*\*/\\textbf{$1}/g; +$file =~ s/__([a-zA-Z][^_]+)__/\\emph{$1}/g; + + +# print output +print $file + + diff --git a/support/easylatex/easylatex/transforms/30autoFractions.pl b/support/easylatex/easylatex/transforms/30autoFractions.pl new file mode 100644 index 0000000000..9a2ca235af --- /dev/null +++ b/support/easylatex/easylatex/transforms/30autoFractions.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it + +$numberRE = '-?\d+(?:\.\d+)?'; +$file =~ s/(^|\W)($numberRE(?:^.)?)\/($numberRE(?:\^.)?)(\W|$)/$1\\frac{$2}{$3}$4/; + +# print output +print $file; + + + + + diff --git a/support/easylatex/easylatex/transforms/30dotsToLdots.pl b/support/easylatex/easylatex/transforms/30dotsToLdots.pl new file mode 100755 index 0000000000..67221cf8d0 --- /dev/null +++ b/support/easylatex/easylatex/transforms/30dotsToLdots.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it + +$file =~ s/(?<!\\)\.\.\./\\ldots /g; +$file =~ s/\\\.\.\./.../g; + +# print output +print $file; + + + + + diff --git a/support/easylatex/easylatex/transforms/30superSubscripts.pl b/support/easylatex/easylatex/transforms/30superSubscripts.pl new file mode 100644 index 0000000000..5640039e6a --- /dev/null +++ b/support/easylatex/easylatex/transforms/30superSubscripts.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl -i.bak + +use English; + + + +use vars qw($EASYLATEXSTORE_RESERVED_WORD @MATH_MODE_SYMBOLS $MATH_MODE_SYMBOL_FILEPATH); + +$EASYLATEXSTORE_RESERVED_WORD = 'EASYLATEXSTORE'; + + + +use vars qw($StorageIndex @Stored); + +$StorageIndex = 0; + + + + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it + +$wordRE = '\w+'; + +$file = storeUntouchables($file); + +#print STDERR "stored file: $file\n\n"; + +$file =~ s/(^|\W)(${wordRE})\^(\w$wordRE)(\W|$)/$1$2^{$3}$4/mg; +$file =~ s/(^|\W)(${wordRE})_(\w$wordRE)(\W|$)/$1$2_{$3}$4/mg; +$file = unstoreUntouchables($file); + +# print output +print $file; + + + + +###################### +# "store" subroutines +###################### + +sub storeUntouchables { + my ($file) = @_; + + $file =~ s/(\\documentclass{.*?})/store($1)/egs; + $file =~ s/\\documentclass{([^}]+)}/'\\documentclass{' . store($1) . '}'/egs; + + + + return $file; +} + +sub unstoreUntouchables { + my ($file) = @_; + + while ($file =~ s/ ?${EASYLATEXSTORE_RESERVED_WORD}-(\d+)-${EASYLATEXSTORE_RESERVED_WORD} ?/$Stored{$1}/egs) {} + + #print STDERR "UNSTOREd:\n\n".$file; + + return $file; +} + + + +sub store { + # got this idea from UseMod + my ($toBeStored) = @_; + + $Stored{$StorageIndex} = $toBeStored; +# print STDERR "STORED: $toBeStored\n"; + +# print STDERR "REPLACEDW: ".${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex . '_'.${EASYLATEXSTORE_RESERVED_WORD}; + + return ' '.${EASYLATEXSTORE_RESERVED_WORD}.'-' . $StorageIndex++ . '-'.${EASYLATEXSTORE_RESERVED_WORD}.' '; +} + + + + diff --git a/support/easylatex/easylatex/transforms/70autoMathMode.pl b/support/easylatex/easylatex/transforms/70autoMathMode.pl new file mode 100644 index 0000000000..20a615c170 --- /dev/null +++ b/support/easylatex/easylatex/transforms/70autoMathMode.pl @@ -0,0 +1,463 @@ +#!/usr/bin/perl -i.bak + +use English; + +use vars qw($EASYLATEXSTORE_RESERVED_WORD @MATH_MODE_SYMBOLS $MATH_MODE_SYMBOL_FILEPATH); + +$EASYLATEXSTORE_RESERVED_WORD = 'EASYLATEXSTORE'; + + + +$MATH_MODE_SYMBOL_FILEPATH = $ARGV[1].'/math_mode_symbol_list.txt'; + + +loadMathModeSymbols(); + + + + + + + +use vars qw($StorageIndex @Stored); + +$StorageIndex = 0; + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; +#$file .= <>; +#print STDERR "********** here's what i got: $file \n\n ************** \n\n"; + + + + +## transform it + +$file = storeMathModes($file); + +$file = autoMathModeEqnArray($file); +$file = storeMathModes($file); + +$file = autoMathModeEqnArrayNoEqualityInFirstEquation($file); +$file = storeMathModes($file); +$file = autoMathModeLeftRight($file); +$file = storeMathModes($file); +$file = autoMathModeFrac($file); +$file = storeMathModes($file); +$file = autoMathModeSqrt($file); +$file = storeMathModes($file); +$file = autoMathModeMathbbEtc($file); +$file = storeMathModes($file); +$file = autoMathModeSuperOrSubscript($file); + +$file = storeMathModes($file); +$file = autoMathModeBinarySymbols($file); + +$file = storeMathModes($file); + +$file = autoMathModeSuperOrSubscript($file); + # done twice to cover this case: (f \circ g)^{-1} + # and this one: a_4 = 2^2 +$file = storeMathModes($file); +$file = autoMathModeSimpleSymbols($file); + +$file = storeMathModes($file); +$file = includeAdjacentParens($file); + + + +$file = autoMathModeUnEscapeEqualsSigns($file); +#print STDERR "auto: $file\n"; +$file = unstoreMathModes($file); + + + +#print STDERR "auto: $file\n"; +print $file; + +sub autoMathModeLeftRight { + my ($file) = @_; + + $file =~ s/(\\left\W.*?\\right\W)/\n\\begin{align*}\n$1\n\\end{align*}\n/gs; + + return $file; +} + + +sub autoMathModeFrac { + my ($file) = @_; + + $file =~ s/(\\frac{[^}]*}{[^}]*})/\$$1\$/g; + + return $file; +} + + +sub autoMathModeSqrt { + my ($file) = @_; + + $file =~ s/(\\sqrt{[^}]*})/\$$1\$/g; + + return $file; +} + + +sub autoMathModeMathbbEtc { + my ($file) = @_; + + $file =~ s/(\\mathbb{[^}]*})/\$$1\$/g; + $file =~ s/(\\mathcal{[^}]*})/\$$1\$/g; + + return $file; +} + + +sub autoMathModeSuperOrSubscript { + my ($file) = @_; + +# print STDERR "superOrSub got $file\n"; + + ### some regular expression "primitives" + my $word_OrCharacterRE = '((?<!\\\\)\\\\?(?:(\w+|.)))'; + my $wordWithoutUnderscores_OrCharacterRE = '((?<!\\\\)\\\\?(?:((?!_)\w)+|.))'; + + my $underscoreWhichIsNotEscapedRE = '(?<!\\\\)_'; + my $carrotWhichIsNotEscapedRE = '(?<!\\\\)\\^'; + + my $bracketsWithoutNestingOrIsolatedCharacterRE = '((?<!\\\\){[^{]*?(?!=\\\\)}|.)(?!\w)'; + + + ### parts of the regular expression for finding subscripts + my $subscriptBaseRE = "(?<!\w)(?!EASYLATEX)$wordWithoutUnderscores_OrCharacterRE"; + my $subscriptOpRE = $underscoreWhichIsNotEscapedRE; + my $subscriptArgRE = $bracketsWithoutNestingOrIsolatedCharacterRE; + + my $subscriptRE = $subscriptBaseRE . $subscriptOpRE . $subscriptArgRE; + + ### parts of the regular expression for finding superscripts + my $superscriptBaseRE = "(?:(?<=[^a-zA-Z0-9_])|(?=\\\\))(?!EASYLATEX)$word_OrCharacterRE"; + my $superscriptOpRE = $carrotWhichIsNotEscapedRE; + my $superscriptArgRE = $bracketsWithoutNestingOrIsolatedCharacterRE; + + my $superscriptRE = $superscriptBaseRE . $superscriptOpRE . $superscriptArgRE; + +# $file =~ s/(${subscriptRE})/\$$1\$/g; +# $file =~ s/(${superscriptRE})/\$$1\$/g; + $file =~ s/(${subscriptRE})/processSuperOrSubscript($1)/ge; + $file =~ s/(${superscriptRE})/processSuperOrSubscript($1)/ge; + +# experimental: +#$file =~ s/${EASYLATEXSTORE_RESERVED_WORD}/processSuperOrSubscript($1)/ge; + + + return $file; +} + +sub processSuperOrSubscript { + my ($block) = @_; + +# print STDERR "proc got $block\n"; + + $block = unstoreMathModes($block); + # so that the next line does something.. + $block =~ s/\$//g; + $block = '$'.$block.'$'; + + return $block; +} + +sub autoMathModeBinarySymbols { + my ($file) = @_; + + @MATH_MODE_BINARY_SYMBOLS = map(quotemeta,@MATH_MODE_BINARY_SYMBOLS); + my $symbol_list = join('|',@MATH_MODE_BINARY_SYMBOLS); + +# print STDERR "pre: $file\n"; + + $file =~ s/(?<!\w)((?:(?!${EASYLATEXSTORE_RESERVED_WORD})\w)+ (?:$symbol_list) (?:(?!${EASYLATEXSTORE_RESERVED_WORD})\w)+)(?:(?!\w)|(?=\\))/\$$1\$/g; + +### now things like "x \mapsto EASYLATEXSTORE" --> "$x \mapsto$ EASYLATEXSTORE" + $file =~ s/(?<!\w)((?:(?!${EASYLATEXSTORE_RESERVED_WORD})\w)+ (?:$symbol_list))(?=\s*${EASYLATEXSTORE_RESERVED_WORD})/\$$1\$/g; + +### now things like "EASYLATEXSTORE \mapsto x" --> "EASYLATEXSTORE $\mapsto x$" + $file =~ s/(?<=${EASYLATEXSTORE_RESERVED_WORD})(\s*)((?:$symbol_list) (?:(?!${EASYLATEXSTORE_RESERVED_WORD})\w)+)(?:(?!\w)|(?=\\))/$1\$$2\$/g; + + +# print STDERR "Repl binary: $file\n"; + + return $file; +} + +sub autoMathModeSimpleSymbols { + my ($file) = @_; + + @MATH_MODE_SYMBOLS = map(quotemeta,@MATH_MODE_SYMBOLS); + my $symbol_list = join('|',@MATH_MODE_SYMBOLS); + + $file =~ s/(?:(?<!\w)|(?=\\))($symbol_list)(?!\w)/\$$1\$/g; + +# print STDERR "Repl simple: $file\n"; + + return $file; +} + + + +# NOTE: this feature may require you to escape some = signs +sub autoMathModeEqnArray { + my ($file) = @_; + + $notEqualsRE = '[^\n=]*'; +# $lineWithOneEqualsRE = "^($notEqualsRE) (?<!\\\\)(?:=|\\\\geq|\\\\leq) ($notEqualsRE)\$"; + $lineWithOneEqualsRE = "(?:($notEqualsRE) (?:=|\\\\geq|\\\\leq|<|>|\\\\propto|\\\\approx)(?<!\\\\=) ($notEqualsRE)\n)"; + +# print STDERR "(?:^|\n\n)($lineWithOneEqualsRE+)(?:\n|$)"; + $file =~ s/(?:^|\n\n)($lineWithOneEqualsRE+)(?:\n|$)/"\n\n".eqnArrayReplaceFn($1)."\n"/eg; + + + return $file; +} + +sub eqnArrayReplaceFn { + $expr = $_[0]; + +# print STDERR "called earfn: $expr\n"; + + $testExpr = $expr; + $testExpr =~ s/\\textrm{.*?}//g; + if ($testExpr =~ /EASYLATEXSTORE/) + { +# print STDERR "not replacing\n"; + return $expr; + } + + + if ($expr =~ /^.*=\s*$/) + { +# print STDERR "not replacing\n"; + return $expr; + } + +# allow multiple \leqs per line? +# if ($expr =~ /\\leq.*\\leq/) +# { +# print STDERR "not replacing\n"; +# return $expr; +# } + + $expr =~ s/\n/\n\\\\/g; + $expr =~ s/(.*)\n\\\\/\1\n/s; + $expr = "\\begin{align*}\n".$expr."\\end{align*}"; + + + + return $expr; +} + + + +# NOTE: this feature may require you to escape some = signs +sub autoMathModeEqnArrayNoEqualityInFirstEquation { + my ($file) = @_; + +# print STDERR "arrayNoEq got: $file\n"; + + $notEqualsRE = '[^\n=]*'; +# $lineWithOneEqualsRE = "^($notEqualsRE) (?<!\\\\)(?:=|\\\\geq|\\\\leq) ($notEqualsRE)\$"; + $lineWithOneEqualsRE = "(?:($notEqualsRE) ?(?:=|\\\\geq|\\\\leq|<|>|\\\\propto|\\\\approx) ($notEqualsRE)\n)"; + $lineWithoutOneEqualsRE = "(?:$notEqualsRE\n)"; + + + $file =~ s/(?:^|\n\n)($lineWithoutOneEqualsRE$lineWithOneEqualsRE+)(?:\n|$)/"\n\n".eqnArrayReplaceFn($1)."\n"/eg; +# $file =~ s/($lineWithOneEqualsRE+)(?:\n|$)/"\n\n".eqnArrayReplaceFn($1)."\n"/eg; + +# print STDERR "arrayNoEq put: $file\n"; + + return $file; +} + + + + + + + + + + + + + +sub autoMathModeUnEscapeEqualsSigns { + my ($file) = @_; + +# @MATH_MODE_SYMBOLS = map(quotemeta,@MATH_MODE_SYMBOLS); +# my $symbol_list = join('|',@MATH_MODE_SYMBOLS); + + $notEqualsRE = '[^\n=]+'; +# $lineWithOneEscapedEqualsRE = "^($notEqualsRE) (?<=\\\\)= ($notEqualsRE)\$"; + +# $file =~ s/\n\n($lineWithOneEqualsRE+)\n\n/"\n\n".unescapeEquals($1)."\n\n"/emg; + $file =~ s/\\=/=/g; + + return $file; + +} + +sub unescapeEquals { + $expr = $_[0]; + + +# print STDERR "Unescaping $expr\n"; + + $expr =~ s/\\=/=/; + + return $expr; +} + + + +sub includeAdjacentParens { + my ($block) = @_; + + $block =~ s/(\(\s* ?${EASYLATEXSTORE_RESERVED_WORD}_\d+_${EASYLATEXSTORE_RESERVED_WORD} ?)/processAdjParensLeft($1)/ge; + $block =~ s/( ?${EASYLATEXSTORE_RESERVED_WORD}_\d+_${EASYLATEXSTORE_RESERVED_WORD} ?\s*\))/processAdjParensRight($1)/ge; + +return $block; +} + +sub processAdjParensLeft { + my ($block) = @_; + + $block =~ /${EASYLATEXSTORE_RESERVED_WORD}_(\d+)_${EASYLATEXSTORE_RESERVED_WORD}/; +$storageID = $1; +$Stored{$storageID} = '('.$Stored{$storageID}; + + $block = substr($block, 1); + +#print STDERR "NEWBLOCK($storageID=$Stored{$storageID}): $block\n"; + + return $block; +} + +sub processAdjParensRight { + my ($block) = @_; + + $block =~ /${EASYLATEXSTORE_RESERVED_WORD}_(\d+)_${EASYLATEXSTORE_RESERVED_WORD}/; +$storageID = $1; +$Stored{$storageID} = $Stored{$storageID} . ')'; + +$block = substr($block, 0, -1); + +#print STDERR "AP $block"; + + return $block; +} + +###################### +# "store" subroutines +###################### + +#currently unused; TODO +sub storeOther { + my ($file) = @_; + + $file =~ s/\\documentclass{([^}]+)}/'\\documentclass{' . store($1) . '}'/egs; + + return $file; +} + +sub storeMathModes { + my ($file) = @_; + + ${notSlashRE_begin} = '(^|(?!\\).)'; + ${notSlashRE} = '(?!\\).'; + + $file =~ s/(\\begin{align}.*?\\end{align})/store($1)/egs; + $file =~ s/(\\begin{align\*}.*?\\end{align\*})/store($1)/egs; + $file =~ s/(\\begin{eqnarray}.*?\\end{eqnarray})/store($1)/egs; + $file =~ s/(\\begin{eqnarray\*}.*?\\end{eqnarray\*})/store($1)/egs; + $file =~ s/(\\begin{equation}.*?\\end{equation})/store($1)/egs; + $file =~ s/(\\begin{equation\*}.*?\\end{equation\*})/store($1)/egs; + $file =~ s/(\\begin{verbatim}.*?\\end{verbatim})/store($1)/egs; + $file =~ s/(\\documentclass{.*?})/store($1)/egs; + $file =~ s/\\documentclass{([^}]+)}/'\\documentclass{' . store($1) . '}'/egs; + + $file =~ s/((?<!\\)\$.*?(?<!\\)\$)/store($1)/egs; + + return $file; +} + +sub unstoreMathModes { + my ($file) = @_; + +# print STDERR "UNSTORE:\n\n".$file; + + while ($file =~ s/ ?${EASYLATEXSTORE_RESERVED_WORD}_(\d+)_${EASYLATEXSTORE_RESERVED_WORD} ?/$Stored{$1}/egs) {} + + return $file; +} + + + +sub store { + # got this idea from UseMod + my ($toBeStored) = @_; + + $Stored{$StorageIndex} = $toBeStored; +# print STDERR "STORED: $toBeStored\n"; + +# print STDERR "REPLACEDW: ".${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex . '_'.${EASYLATEXSTORE_RESERVED_WORD}; + + return ' '.${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex++ . '_'.${EASYLATEXSTORE_RESERVED_WORD}.' '; +} + + +###################### +# utility subroutines +###################### + + +sub loadMathModeSymbols { + +#I got the symbol tables by doing this on my own machine: +# cd /usr/share/texmf/tex/latex +# grep -r DeclareMathSymbol * > /tmp/t +# perl -pi -e 's/.*?:\s*\\DeclareMathSymbol{?(\\\w+)}?(\s|{).*/$1/g' /tmp/t +# perl -pi -e 's/.*?:\s*(\\\w+)(\s|$)/$1/gm' /tmp/t +# perl -i -e 'while (<>) {if (!/:/) {print $_;}}' /tmp/t +# +# cd {src directory of "The not so Short Introduction to LaTeX"} +# cat lssym.tex | perl -e 'undef $/; $_ = <>; while (/(?:{(\\\w+)}|\\verb\|(\\\w+)\|)/g) {print "$1$2\n";}' lssym.tex >> /tmp/t +# +# sort /tmp/t > /tmp/t2 +# uniq /tmp/t2 > /tmp/t +# grep -v '\\DeclareMathSymbol' /tmp/t > /tmp/t2 +# +#and then I moved /tmp/t2 into the file math_mode_symbol_list.txt +# +# and then manually added "\ldots" at the end of the file +# + + $INPUT_RECORD_SEPARATOR = "\n"; + + open(SYMBOLFILE, $MATH_MODE_SYMBOL_FILEPATH) or die "Can't open list of math mode symbols at $MATH_MODE_SYMBOL_FILEPATH"; + while ($line = <SYMBOLFILE>) + { + chomp $line; + push(@MATH_MODE_SYMBOLS,$line); + push(@MATH_MODE_BINARY_SYMBOLS,$line); + } + close(SYMBOLFILE); + + push(@MATH_MODE_BINARY_SYMBOLS,'+'); + push(@MATH_MODE_BINARY_SYMBOLS,'-'); + push(@MATH_MODE_BINARY_SYMBOLS,'*'); + push(@MATH_MODE_BINARY_SYMBOLS,'/'); + push(@MATH_MODE_BINARY_SYMBOLS,'='); + + +} + diff --git a/support/easylatex/easylatex/transforms/80autoAlignEquations.pl b/support/easylatex/easylatex/transforms/80autoAlignEquations.pl new file mode 100755 index 0000000000..b034018c72 --- /dev/null +++ b/support/easylatex/easylatex/transforms/80autoAlignEquations.pl @@ -0,0 +1,264 @@ +#!/usr/bin/perl -i.bak + +use English; + + +$EASYLATEXSTORE_RESERVED_WORD = 'EASYLATEXSTORE'; +use vars qw($StorageIndex @Stored); +$StorageIndex = 0; + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + + #print STDERR "I got:**********************\n".$file."***************\n"; + +## transform it + +$equalsRE = '(?:=|\\\\Rightleftarrow|\\\\Rightarrow|\\\\Leftarrow|\\\\geq|\\\\leq)'; +#$equalsRE = '='; +#$mathLinesepStuffRE = '(?:\\\\Rightleftarrow|\\\\Rightarrow|\\\\Leftarrow)?'; +$mathLinesepStuffRE = ''; + + + +my $beginMathRE = '\\\\begin{(?:eqnarray|align)\\*?}'; +my $endMathRE = '\\\\end{(?:eqnarray|align)\\*?}'; + +#my $notEqualsDoubleBackslashNotAmpersandRE = '(?:(?!\\\\\\\\)[^=&\n])*'; +my $notEqualsDoubleBackslashNotAmpersandRE = '(?:(?!\\\\\\\\)(?!\\\\)(?!'.$equalsRE.')[^\n&])*'; +my $notEqualsDoubleBackslashNotAmpersandRE = '(?:(?!\\\\\\\\)(?!'.$equalsRE.')[^\n&])*'; + ## confusing!! aloowed ampersand without changing name! +#my $doubleBlackslashOrEndRE = '(?:\n\\\\\\\\|\n)'; +my $doubleBlackslashOrEndRE = '(?:\n\\\\\\\\'.$mathLinesepStuffRE.'|\n)'; + + +my $lineInMathModeRE = '(?:(?!\\\\\\\\).)*' . $doubleBlackslashOrEndRE; +my $lineWithOneEqualsRE = $notEqualsDoubleBackslashNotAmpersandRE . '(?:'.$equalsRE.'|\\\\geq|\\\\leq)' . $notEqualsDoubleBackslashNotAmpersandRE . $doubleBlackslashOrEndRE; + + + +$mainRegexp = "($beginMathRE\n?$lineInMathModeRE(?:$lineWithOneEqualsRE(?:$doubleBlackslashOrEndRE)*)+$endMathRE\n)"; +#$mainRegexp = "($beginMathRE\n$lineInMathModeRE$notEqualsDoubleBackslashNotAmpersandRE(?:$equalsRE)$notEqualsDoubleBackslashNotAmpersandRE$doubleBlackslashOrEndRE(.|\n)*?$endMathRE\n)"; +#$mainRegexp = "($beginMathRE\n$lineInMathModeRE$notEqualsDoubleBackslashNotAmpersandRE(?:$equalsRE)$notEqualsDoubleBackslashNotAmpersandRE(.|\n)*?$endMathRE\n)"; +#$mainRegexp = "(($beginMathRE\n)$lineInMathModeRE((?:$notEqualsDoubleBackslashNotAmpersandRE(?:$equalsRE)$notEqualsDoubleBackslashNotAmpersandRE$doubleBlackslashOrEndRE)+)(.|\n)*?$endMathRE\n)"; + + + +#print STDERR "REGEXP=" . $mainRegexp . "\n"; + + +#$file =~ /$mainRegexp/; + +#$file =~ s/($beginMathRE\n$lineInMathModeRE(?:$lineWithOneEqualsRE)+$endMathRE\n)/processEqnArray($1)/eg; + +#print STDERR "1: $1\n\n"; +#print STDERR "2: $2\n\n"; +#print STDERR "3: $3\n\n"; +#print STDERR "4: $4\n\n"; +#print STDERR "5: $4\n\n"; +#print STDERR "6: $4\n\n"; + +$file = storeTexts($file); + + #print STDERR $file; +$file =~ s/$mainRegexp/processEqnArray($1)/eg; +$file = unstoreTexts($file); + +print $file; + +#print STDERR "I sent:**********************\n".$file."***************\n"; + +############## +# end MAIN +############## + + + + + + + + + +sub processEqnArray { + my ($block) = @_; + + #print STDERR "**************\nEntered EqnArray\n****************\n"; + #print STDERR $block; + +$block = unstoreTexts($block); + +# if (! ($block =~ /$beginMathRE\n$lineWithOneEqualsRE(?:$lineWithOneEqualsRE)+$endMathRE\n/) ) +# { +# $block =~ s/(}\n?)/$1&/; ## right after the \begin{}, add a '&' +# } + + $block = alignEquals($block); + $block = alignTextAtBeginningOrEndOfLine($block); + + if ($block =~ /$beginMathRE\n\s*[^&].*\n(\s*\\\\\s*&.*\n)+$endMathRE\n/) + { + #print STDERR "*\n*\n*\nyes\n\n"; + $block =~ s/(}\n?)/$1&/; ## right after the \begin{}, add a '&' + } + + + $block = blankLinesToIntertext($block); + $block = removeLinefeedAfterBeginOrIntertext($block); + + + return $block; +} + + +# sub processEqnArrayAndIndentFirstLine { +# my ($block) = @_; + +# print STDERR $block; + +# $block =~ s/(}\n?)/$1&/; ## right after the \begin{}, add a '&&' +# $block = processEqnArray($block); + +# return $block; +# } + + +sub alignEquals { + my ($block) = @_; + + + #print STDERR "AEb: $block"; + $block = storeTexts($block); + +# $block =~ s/(?<!\\\\)($equalsRE)/&\1/g; + $block =~ s/($equalsRE)/&\1/g; + #$block =~ s/\\leq/&\\leq/g; + #$block =~ s/\\geq/&\\geq/g; + + $block = unstoreTexts($block); + + #print STDERR "AEf: $block"; + + return $block; +} + + +sub alignTextAtBeginningOrEndOfLine { + my ($block) = @_; + + $block = alignTextAtBeginningOfLine($block); + $block = alignTextAtEndOfLine($block); + + return $block; +} + +sub alignTextAtBeginningOfLine { + my ($block) = @_; + + $textAtBeginningOfLineRE = '^(\\\\\\\\\\\\textrm{[^}]*?)}'; + +### if ($block =~ s/^((?:\\\\)*\s*\\textrm{[^}]*?)}/$1 } & /mg) {print STDERR "yes!\n"}; +# if ($block =~ s/^(\\\\\\textrm{[^}]*?)}/$1 } & /mg) {print STDERR "yes!\n"}; + if ($block =~ /$textAtBeginningOfLineRE/mg) + { +# print STDERR "found it!\n"; + + $block =~ s/$textAtBeginningOfLineRE/$1 } && /mg; + $block =~ s/\\\\/\\\\&& /g ; + $block =~ s/(}\n?)/$1&&/; ## right after the \begin{}, add a '&&' + $block =~ s/^\\\\&& \s*\\textrm{/\\\\ \\textrm{/mg; + } + + + return $block; +} + +sub alignTextAtEndOfLine { + my ($block) = @_; + +# print STDERR $block; + + $block =~ s/\\textrm{([^}]*?}\s*)$/& \\textrm{ $1/mg; + # if a line ends in \textrm{...} + # then indent the \textrm, and add a space to the text inside of it + + return $block; +} + + +sub blankLinesToIntertext { + my ($block) = @_; + + #print STDERR $block; + $block =~ s/\\\\\n/\\\\\\intertext{}\n/mg; + + + return $block; +} + +sub removeLinefeedAfterBeginOrIntertext { + my ($block) = @_; + + #print STDERR $block; + + $block =~ s/(\\begin{align}(?:\\label{[^}]+})?|\\intertext{[^}]*})\n\\\\/$1/mg; + + + return $block; +} + + + + + + + +########### +# "store" subroutines +########### + + +###################### +# "store" subroutines +###################### + +sub storeTexts { + my ($file) = @_; + +# print STDERR "TESTING for storage:$file\n\n"; + + $file =~ s/(\\textrm{[^}]*})/store($1)/egs; + $file =~ s/((?<!\\begin)(?<!\\end){[^}]*})/store($1)/egs; + + return $file; +} + +sub unstoreTexts { + my ($file) = @_; + +# print STDERR "UNSTORE:\n\n".$file; + + while ($file =~ s/${EASYLATEXSTORE_RESERVED_WORD}_(\d+)_${EASYLATEXSTORE_RESERVED_WORD}/$Stored{$1}/egs) {} + + return $file; +} + + + +sub store { + # got this idea from UseMod + my ($toBeStored) = @_; + + $Stored{$StorageIndex} = $toBeStored; + #print STDERR "STORED: $toBeStored\n"; + +# print STDERR "REPLACEDW: ".${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex . '_'.${EASYLATEXSTORE_RESERVED_WORD}; + + return ${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex++ . '_'.${EASYLATEXSTORE_RESERVED_WORD}; +} + + + + diff --git a/support/easylatex/easylatex/transforms/80autoItemize.pl b/support/easylatex/easylatex/transforms/80autoItemize.pl new file mode 100755 index 0000000000..6d751eabcd --- /dev/null +++ b/support/easylatex/easylatex/transforms/80autoItemize.pl @@ -0,0 +1,99 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it +$lineBeginningWithParensRE = '^\(.*?\)\W*\w+.*$'; +$wordOrDot = '(?:\w|\.)'; +$lineBeginningWithNumberedHalfParensRE = "^$wordOrDot+?\\).*\$"; +$lineBeginningWithStarRE = '^\*+ .*$'; +$lineBeginningWithNumberSignRE = '^#+ .*$'; + +#TODO: Embedded lists + +$file =~ s/($lineBeginningWithParensRE\n($lineBeginningWithParensRE\n)+)/itemizeParens($1)/mge; + +$file =~ s/($lineBeginningWithNumberedHalfParensRE\n($lineBeginningWithNumberedHalfParensRE\n)+)/itemizeNumberedHalfParens($1)/mge; + +$file =~ s/($lineBeginningWithStarRE\n($lineBeginningWithStarRE\n)+)/itemizeStar($1)/mge; + +$file =~ s/($lineBeginningWithNumberSignRE\n($lineBeginningWithNumberSignRE\n)+)/itemizeNumberSign($1)/mge; + + + + + +# print output +print $file; + + + + + +############ +# END OF MAIN +############ + + + + +sub itemizeParens { + my $expr = $_[0]; + + $expr =~ s/^(\(.*?\))/\\item[$1]/mg; + + $expr = "\\begin{itemize}\n".$expr."\\end{itemize}\n"; + + return $expr; +} + + +sub itemizeStar { + # this is essential the same as "itemizeNumberSign" + + my $expr = $_[0]; + + $expr =~ s/^\* /\\item /mg; + $expr =~ s/^\*\*/*/mg; + + $expr = "\\begin{itemize}\n".$expr."\\end{itemize}\n"; + + # recurse + $expr =~ s/(($lineBeginningWithStarRE\n)+)/itemizeStar($1)/mge; + + return $expr; +} + +sub itemizeNumberSign { + # this is essentially the same as "itemizeStar" + + my $expr = $_[0]; + + $expr =~ s/^\# /\\item /mg; + $expr =~ s/^\#\#/#/mg; + + $expr = "\\begin{enumerate}\n".$expr."\\end{enumerate}\n"; + + # recurse + $expr =~ s/(($lineBeginningWithNumberSignRE\n)+)/itemizeNumberSign($1)/mge; + + return $expr; +} + + + +sub itemizeNumberedHalfParens { + my $expr = $_[0]; + + $expr =~ s/^(.*?\))/\\item[$1]/mg; + + $expr = "\\begin{itemize}\n".$expr."\\end{itemize}\n"; + + return $expr; +} + + diff --git a/support/easylatex/easylatex/transforms/80easyMatrices.pl b/support/easylatex/easylatex/transforms/80easyMatrices.pl new file mode 100755 index 0000000000..8335ae9151 --- /dev/null +++ b/support/easylatex/easylatex/transforms/80easyMatrices.pl @@ -0,0 +1,239 @@ +#!/usr/bin/perl -i.bak + +use English; + + use vars qw($EASYLATEXSTORE_RESERVED_WORD @MATH_MODE_SYMBOLS $MATH_MODE_SYMBOL_FILEPATH); + + $EASYLATEXSTORE_RESERVED_WORD = 'EASYLATEXSTORE'; + use vars qw($StorageIndex @Stored); + + $StorageIndex = 0; + + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it + +$openingSquareBracketRE = '(?:^|(?<=\s))\\[\\['; + # opening square bracket, either at the beginning of a line + # or preceded by whitespace (note: this won't trigger if preceded by + # brackets either) +$closingSquareBracketRE = '(?<!\\\\)\\]\\]'; + +$file =~ s/${openingSquareBracketRE}([^\]\]]*?)${closingSquareBracketRE}'/matlabStyleMatrixTransposeReplace($1)/emgs; # do transpose replaces first + +$file =~ s/${openingSquareBracketRE}([^\]\]]*?)${closingSquareBracketRE}/matlabStyleMatrixReplace($1)/emgs; # now do the normal ones + + +## unescape \[ and \] s (which the user might use to escape things that weren't supposed to be easy matrices) +#$file =~ s/\\\[/[/g; +#$file =~ s/\\]/]/g; + +$file = easyMatricesToMathMode($file); + + +## print output +print $file; +#print "\n"; +#print STDERR $file; + + +###################### +# subroutines +###################### + +sub matlabStyleMatrixReplace { + my ($expr) = @_; + + my @rows; + my $out; + + @rows = readInMatlabStyleMatrix($expr); + $out = matrixToLatex(@rows); + + return $out; +} + +sub matlabStyleMatrixTransposeReplace { + my ($expr) = @_; + + my @rows; + my $out; + + @rows = readInMatlabStyleMatrix($expr); + @rows = transpose(@rows); + $out = matrixToLatex(@rows); + + return $out; +} + + +sub readInMatlabStyleMatrix { + my ($expr) = @_; + + my @inputRows; + my @inputCols; + my @rows; + my @cols; + my ($colIndex, $rowIndex); + my $row; + my $cols; + + @inputRows = split(/;/, $expr); + for ($rowIndex = 0; $rowIndex <= $#inputRows; $rowIndex++) { + $row = $inputRows[$rowIndex]; + $cols = []; $colIndex = 0; + @inputCols = split(/ /, $row); + foreach $col (@inputCols) { + if ($col =~ /^\W*$/) {next;} # bypass whitespace + if ($col =~ /&/) {$cols[$colIndex++] = ''; next;} + # bypass column separators; + # this can be used to indicate an empty + # column. + + $cols->[$colIndex++] = $col; + } + $rows[$rowIndex] = $cols; + } + +# use Data::Dumper; +# print Dumper(@rows); + +# print "ir = $#inputRows\n"; + + return @rows; +} + +sub matrixToLatex { + my @rows = @_; + + my @cols; + my ($row, $out); + my $colCount; + my $colSpecifier; + my $i; + my $out; + + foreach $row (@rows) { + @cols = @$row; + $colCount = $#cols + 1; + # yeah, okay, so we do this for every row + # and we only need to do it once! + foreach $col (@cols) { + $out .= "$col & "; + + } + $out = substr($out,0,-3); + ## STRIP OFF THE EXTRA & THAT WE PUT AFTER THE LAST COLUMN + $out .= "\n".'\\\\ '; + } + + ## STRIP OFF THE \\ THAT WE PUT AFTER THE LAST LINE OF THE MATRIX + $out = substr($out,0,-3); + + for ($i = 0; $i < $colCount; $i++) { + $colSpecifier .= 'l'; + } + + $out = '\left[ \begin{array}{'.$colSpecifier.'}'."\n".' ' . $out . '\end{array} \right]'; + +# print STDERR "**************$out\n"; + + return $out; +} + + +sub transpose { + my @inRows = @_; + my ($rowIndex,$colIndex); + my @outRows; + + + #TODO: put in error checking in case the # of columns in each row is not the same + + + + my @firstRow = @{$inRows[0]}; + + + + for($rowIndex=0;$rowIndex<=$#firstRow; $rowIndex++) + { + @outRows[$rowIndex] = []; + for($colIndex=0;$colIndex<=$#inRows; $colIndex++) + { +# print STDERR "($rowIndex,$colIndex)"; + @outRows[$rowIndex]->[$colIndex] = $inRows[$colIndex]->[$rowIndex]; + } + } + +# use Data::Dumper; +# print STDERR Dumper(@outRows); + + + + return @outRows; +} + +sub easyMatricesToMathMode { + my ($file) = @_; + + + $file = storeMathModes($file); + $file =~ s/(\\left\W.*?\\right\W)/\n\\begin{align*}\n$1\n\\end{align*}\n/gs; + $file = unstoreMathModes($file); + + return $file; +} + + +###################### +# store subroutines +###################### + + +sub storeMathModes { + my ($file) = @_; + + ${notSlashRE_begin} = '(^|(?!\\).)'; + ${notSlashRE} = '(?!\\).'; + + $file =~ s/(\\begin{align}.*?\\end{align})/store($1)/egs; + $file =~ s/(\\begin{align\*}.*?\\end{align\*})/store($1)/egs; + $file =~ s/(\\begin{eqnarray}.*?\\end{eqnarray})/store($1)/egs; + $file =~ s/(\\begin{eqnarray\*}.*?\\end{eqnarray\*})/store($1)/egs; + $file =~ s/(\\begin{equation}.*?\\end{equation})/store($1)/egs; + $file =~ s/(\\begin{equation\*}.*?\\end{equation\*})/store($1)/egs; + $file =~ s/(\\begin{verbatim}.*?\\end{verbatim})/store($1)/egs; + + $file =~ s/((?<!\\)\$.*?(?<!\\)\$)/store($1)/egs; + + return $file; +} + +sub unstoreMathModes { + my ($file) = @_; + +# print STDERR "UNSTORE:\n\n".$file; + + while ($file =~ s/ ?${EASYLATEXSTORE_RESERVED_WORD}_(\d+)_${EASYLATEXSTORE_RESERVED_WORD} ?/$Stored{$1}/egs) {} + + return $file; +} + + + +sub store { + # got this idea from UseMod + my ($toBeStored) = @_; + + $Stored{$StorageIndex} = $toBeStored; +# print STDERR "STORED: $toBeStored\n"; + +# print STDERR "REPLACEDW: ".${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex . '_'.${EASYLATEXSTORE_RESERVED_WORD}; + + return ' '.${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex++ . '_'.${EASYLATEXSTORE_RESERVED_WORD}.' '; +} diff --git a/support/easylatex/easylatex/transforms/85sweepHalfEquationsIntoAdjacentMathMode.pl b/support/easylatex/easylatex/transforms/85sweepHalfEquationsIntoAdjacentMathMode.pl new file mode 100755 index 0000000000..dac1340e48 --- /dev/null +++ b/support/easylatex/easylatex/transforms/85sweepHalfEquationsIntoAdjacentMathMode.pl @@ -0,0 +1,125 @@ +#!/usr/bin/perl -i.bak + +use English; + +use vars qw(@MATH_MODE_SYMBOLS $MATH_MODE_SYMBOL_FILEPATH); + +$MATH_MODE_SYMBOL_FILEPATH = $ARGV[1].'/math_mode_symbol_list.txt'; + + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR "*****here's what i got ******\n$file\n"; + +## transform it + +loadMathModeSymbols(); + +@MATH_MODE_BINARY_SYMBOLS = map(quotemeta,@MATH_MODE_BINARY_SYMBOLS); +my $symbol_list = join('|',@MATH_MODE_BINARY_SYMBOLS); + +$beginMathModeRE = '(?:\\\\begin{(?:equation|align|eqnarray)\\*?}|\\$)'; +$endMathModeRE = '(?:\\\\end{(?:equation|align|eqnarray)\\*?}|\\$)'; +$beginMathModeWithCaptureRE = '(?:\\\\begin{((?:equation|align|eqnarray)\\*?)})'; +#$beginMathModeWithCaptureRE = '(?:\\\\begin{((?:eq\\$)'; +#$endMathModeWithCaptureRE = '(?:\\\\end{((?:equation|align|eqnarray)\\*?)}|\\$)'; +$endMathModeWithCaptureRE = '(?:\\\\end{((?:equation|align|eqnarray)\\*?)}|\\$)'; + +$file =~ s/\$\$//g; + + +$file =~ s/(?<!\w)(\w (?:$symbol_list))(\s+$beginMathModeRE)/\$$1\$$2/gs; + +$file =~ s/($endMathModeRE\s+)((?:$symbol_list) \w)(?!\w)/$1\$$2\$/gs; + +#$file =~ s/$endMathModeWithCaptureRE(\s+)\\begin{\1}/oneNewlineOrNothing($2)/esg; + +$file =~ s/\$(\s+)\$/oneNewlineOrNothing($1)/esg; + + +while ($file =~ s/\$([^\$]+)\$(\s*)$beginMathModeWithCaptureRE\s*/"\\begin{$3}".$1.oneNewlineOrNothing($2).' '/esg) +{ +# print STDERR "FOUND: $1, $2, $3\n\n\n"; +} + +# print output +print $file; +#print STDERR "Here's what I put: $file\n"; + + +sub oneNewlineOrNothing { + my ($expr) = @_; + + my $count = 0; + my $i; + my $whitespace = ''; + + while ($expr =~ /\n/sg) {$count++;} + + if ($expr =~ /\s/) {$whitespace = ' '}; + + if ($count == 0) {$expr = '';} + else { + $expr = "\n"; + for ($i = 0; $i < ($count - 1); $i++) { + $expr .= '\\\\ '; + } + } + + $expr = $whitespace . $expr; + + +# print STDERR "*** count = $count; expr: $expr ***\n"; + + return $expr; +} + + +###################### +# utility subroutines +###################### + + +sub loadMathModeSymbols { + +#I got the symbol tables by doing this on my own machine: +# cd /usr/share/texmf/tex/latex +# grep -r DeclareMathSymbol * > /tmp/t +# perl -pi -e 's/.*?:\s*\\DeclareMathSymbol{?(\\\w+)}?(\s|{).*/$1/g' /tmp/t +# perl -pi -e 's/.*?:\s*(\\\w+)(\s|$)/$1/gm' /tmp/t +# perl -i -e 'while (<>) {if (!/:/) {print $_;}}' /tmp/t +# +# cd {src directory of "The not so Short Introduction to LaTeX"} +# cat lssym.tex | perl -e 'undef $/; $_ = <>; while (/(?:{(\\\w+)}|\\verb\|(\\\w+)\|)/g) {print "$1$2\n";}' lssym.tex >> /tmp/t +# +# sort /tmp/t > /tmp/t2 +# uniq /tmp/t2 > /tmp/t +# grep -v '\\DeclareMathSymbol' /tmp/t > /tmp/t2 +# +#and then I moved /tmp/t2 into the file math_mode_symbol_list.txt + + + $INPUT_RECORD_SEPARATOR = "\n"; + + open(SYMBOLFILE, $MATH_MODE_SYMBOL_FILEPATH) or die "Can't open list of math mode symbols at $MATH_MODE_SYMBOL_FILEPATH"; + while ($line = <SYMBOLFILE>) + { + chomp $line; + push(@MATH_MODE_SYMBOLS,$line); + push(@MATH_MODE_BINARY_SYMBOLS,$line); + } + close(SYMBOLFILE); + + push(@MATH_MODE_BINARY_SYMBOLS,'+'); + push(@MATH_MODE_BINARY_SYMBOLS,'-'); + push(@MATH_MODE_BINARY_SYMBOLS,'*'); + push(@MATH_MODE_BINARY_SYMBOLS,'/'); + push(@MATH_MODE_BINARY_SYMBOLS,'='); + +} + + + diff --git a/support/easylatex/easylatex/transforms/90addHeaderAndFooter.pl b/support/easylatex/easylatex/transforms/90addHeaderAndFooter.pl new file mode 100644 index 0000000000..ac8fff945e --- /dev/null +++ b/support/easylatex/easylatex/transforms/90addHeaderAndFooter.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl -i.bak + +use English; +use Getopt::Declare; + +###################### +# DEFINE GLOBAL CONSTANTS +###################### + +use vars qw($EASYLATEX_DIR @TRANSFORM_PATHS $LATEX_HEADER $LATEX_FOOTER $PARTIAL_DOCUMENT); + + +$DEFAULT_DOCUMENTCLASS = <<'EOF' ; +\documentclass{article} +EOF + +$DEFAULT_USEPACKAGE = <<'EOF' ; +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{psfrag} +EOF + +@usepackage_list = qw(amsmath amsfonts amssymb psfrag); +%usepackage_options = qw(graphicx dvips); + +$BEGIN_DOCUMENT = <<'EOF' ; + +\begin{document} + +EOF + +# todo: eliminate DEFAULT_USEPACKAGE +$LATEX_HEADER_FULL = $DEFAULT_DOCUMENTCLASS. $DEFAULT_USEPACKAGE. $BEGIN_DOCUMENT; + + +$END_DOCUMENT = <<'EOF' ; + +\end{document} +EOF + + +$LATEX_FOOTER = $END_DOCUMENT; + + +###################### +# BEGIN MAIN +###################### + +#print STDERR "DBG2: " . join(@ARGV); + +$argSpecification = q( + --partial This file is not a full LaTeX document, just a partial one (to be \\include'd, for instance) + {$PARTIAL_DOCUMENT = 1;} + ); + + +$args = new Getopt::Declare($argSpecification); + +if ($PARTIAL_DOCUMENT) { + #print STDERR 'PARTIAL DBG\n\n'; + exit; +} + + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +if (!($file =~ /\\documentclass/)) +{ +# $file = $LATEX_HEADER_FULL . $file . $LATEX_FOOTER; + $file = $DEFAULT_DOCUMENTCLASS . $file; +} + +if (!($file =~ /\\begin{document}/)) +{ + + $file =~ s/(.*\\documentclass{[^}]*}[^\n]*\n)/$1$BEGIN_DOCUMENT/s; + $file = $file . $END_DOCUMENT; + + + ## move usepackages, title, author, newcommand to within preamble + my @usepackages_in_file; + while ($file =~ s/(\\begin{document}.*?)(\\usepackage(\[[^\]]*])?{[^}]+}[^\n]*|\\title{[^}]*}|\\author{[^}]*}|\\newcommand{[^}]*}(?:\[[^\]]*\])?{[^}]*}[^\n]*(?=\n))/$1/sg) { + $pkg = $2; + #push(@usepackages_in_file, $1); + $file =~ s/(.*\\documentclass{[^}]*}[^\n]*\n)/$1$pkg\n/s; + + ##NOTE: currently \newcommand is not moved, b/c it was protected from processing in easylatex.pl + + + } +} + +# TODO: add code to add usepackages +foreach $pkg (@usepackage_list) { + if (!($file =~ /\\usepackage(\[[^\]]*])?{$pkg}/)) + { + if ($usepackage_options{$pkg}) { + $opt = $usepackage_options{$pkg}; + $file =~ s/\\begin{document}/\\usepackage[$opt]{$pkg} %% pkg required by EasyLatex\n\\begin{document}/; + } + else { + $file =~ s/\\begin{document}/\\usepackage{$pkg} %% pkg required by EasyLatex\n\\begin{document}/; + + } +#print STDERR "*********** $pkg"; + } + +} + +if (!($file =~ /\\usepackage(\[[^\]]*])?{graphicx}/) && !($file =~ /\\documentclass(\[[^\]]*\])?{prosper}/) && !($file =~ /\\dontusepackage{graphicx}/)) +{ + $file =~ s/\\begin{document}/\\usepackage[dvips]{graphicx} %% pkg required by EasyLatex\n\\begin{document}/; + #print STDERR "*********** $pkg"; +} + + +$file =~ s/\\dontusepackage{[^}]+}//g; + + +print $file; diff --git a/support/easylatex/easylatex/transforms/90doublePercentIsCommentSymbol.pl b/support/easylatex/easylatex/transforms/90doublePercentIsCommentSymbol.pl new file mode 100755 index 0000000000..efb99d1faa --- /dev/null +++ b/support/easylatex/easylatex/transforms/90doublePercentIsCommentSymbol.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl -i.bak + +use English; + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +$file =~ s/(?<!%)%(?!%)/\\%/g; +$file =~ s/%%/%/g; + + +print $file; + diff --git a/support/easylatex/easylatex/transforms/90easyFigures.pl b/support/easylatex/easylatex/transforms/90easyFigures.pl new file mode 100755 index 0000000000..f5cc73a73c --- /dev/null +++ b/support/easylatex/easylatex/transforms/90easyFigures.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -i.bak + +use English; + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +$file =~ s/\\fig(?:\[(.+?)\])?{(.+?)}(?:{(.+?)})?(?:{(.+?)})?/easyFigure($2,$1, $3, $4)/ge; +$file =~ s/\\cfig(?:\[(.+?)\])?{(.+?)}(?:{(.+?)})?(?:{(.+?)})?/easyFigure($2,$1 . ',center', $3, $4)/ge; + + + +print $file; + + + + +sub easyFigure { + my ($file, $opts, $labelText, $captionText) = @_; + + # DEFAULTS + my $centering = ''; + my @includegraphicsOptions = (); + my $includegraphicsOptions = ''; + + @opts = split(/,/, $opts); + foreach $opt (@opts) { +# print STDERR $opt; +# print STDERR "\n\n"; + + if ($opt eq 'center') { + $center = '\\centering'; + } + else { + push(@includegraphicsOptions, $opt); +#print STDERR ('[' . join(',', @includegraphicsOptions) . ']\n\n'); + + } + + } + + if ($captionText) { + $caption = "\\caption{$captionText}"; + } + + if ($labelText) { + $label = "\\label{$labelText}"; + } + + if ($#includegraphicsOptions >= 0) { + $includegraphicsOptions = '[' . join(',', @includegraphicsOptions) . ']'; + #print STDERR "$includegraphicsOptions\n\n"; + } + + + my $ret = <<EOF; +\\begin{figure}$label +$center \\includegraphics${includegraphicsOptions}{$file} $caption +\\end{figure} +EOF + + chop($ret); + #print STDERR $ret; + return $ret; + +} diff --git a/support/easylatex/easylatex/transforms/90graphs.pl b/support/easylatex/easylatex/transforms/90graphs.pl new file mode 100755 index 0000000000..1a5b7d6a4b --- /dev/null +++ b/support/easylatex/easylatex/transforms/90graphs.pl @@ -0,0 +1,192 @@ +#!/usr/bin/perl -i.bak + +# In case the version of File::Spec installed on this system is too old for File::Temp to use +BEGIN { + unshift(@INC, "."); +} + + +#todo: take off trailing linefeeds inside a \begin{graph}\end{graph}; they cause errors + +use English; +use File::Temp qw/ :POSIX /; +use vars qw ($graphCounter $filenameBase); +$graphCounter = 0; + + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + + +#print STDERR "*********** I got: $file\n"; + +$DONT_CENTER = 1; +#if ($file =~ /\\dontcentergraphs/) {$DONT_CENTER = 1;} + +$file =~ s/\\dontcentergraphs//g; + +## transform it + +$file =~ s/\\begin{graph}\[nc\](.*?)\\end{graph}/processGraph($1, 'digraph', 0)/sge; +$file =~ s/\\begin{ugraph}\[nc\](.*?)\\end{ugraph}/processGraph($1, 'undirected graph', 0)/sge; + +if (! $DONT_CENTER) { + $file =~ s/\\begin{graph}(.*?)\\end{graph}/processGraph($1, 'digraph', 1)/sge; + $file =~ s/\\begin{ugraph}(.*?)\\end{ugraph}/processGraph($1, 'undirected graph', 1)/sge; +} else { + $file =~ s/\\begin{graph}(.*?)\\end{graph}/processGraph($1, 'digraph', 0)/sge; + $file =~ s/\\begin{ugraph}(.*?)\\end{ugraph}/processGraph($1, 'undirected graph', 0)/sge; +} + +#TODO: remove DONT_CENTER primitive... it's just for dana for this paper.. + +# print output +print $file; + + +############### +# end of MAIN +############### + +sub processGraph { + my ($block, $type, $centered) = @_; + + + + $block =~ s/(\\begin{align\*?}.*?\\end{align\*?}\n?)/removeNewlines($1)/sge; + $block =~ s/\\begin{align\*?}(.*?)\\end{align\*?}/\$\1\$/g; + + $block =~ s/((?:\$[^\$\n]*\$)*[^\$]*)\$([^\$]*)\$/$1.'$'.removeNewlines($2).'$'/ge; + +# print STDERR $block; + + my $l = length($block); + $filenameBase = "easyLatexGraph${graphCounter}$l"; + + if ($type eq 'digraph') { + $block = "digraph $filenameBase {\n".$block."\n}"; + ladot($block, 'dot'); + } + elsif ($type eq 'undirected graph') { + $block = "graph $filenameBase {\n".$block."\n}"; + ladot($block, 'neato'); + } + + $graphCounter = $graphCounter + 1; + rename("$filenameBase.ps", "$filenameBase.eps"); + + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) + = stat("$filenameBase.tex"); + + if (! $size) { + unlink("$filenameBase.tex"); + if ($centered) { + return "\\begin{center}\\includegraphics{$filenameBase.eps}\\end{center}"; + } else { + return "\\includegraphics{$filenameBase.eps}"; + } + } + else + { + if ($centered) { + return "\\begin{center}\\input{$filenameBase.tex}\n\\includegraphics{$filenameBase.eps}\\end{center}"; + } else { + return "\\input{$filenameBase.tex}\n\\includegraphics{$filenameBase.eps}"; + } + } +} + +sub removeNewlines { + my ($block) = @_; + + $block =~ s/\n//g; + + return $block; +} + + + + + +# ladot version 2003-03-31 +# by Brighten Godfrey +# + + +sub ladot { + + my ($block, $graphProgramName) = @_; + +# print STDERR "Ladot got:\n$block\n"; + + my @lines = split(/\n/, $block); + + %paststubs = (); + + + ($dotout, $dotoutFilename) = tmpnam(); + +# Open output file +# open(DOTOUT, ">/tmp/$basename.dot"); + open(TEXOUT, ">$filenameBase.tex"); + + foreach $line (@lines) + { + $line .= "\n"; + + # process each TEX{...}TEX segment on this line +# while ($line =~ /(TEX(\((\d+)\))?\{(.*?)\}TEX)/) { + while ($line =~ /(\$.*?\$)(\((\d+)\))?/) { +# print "LINE: $line"; + $sizehint = $3; +# print "SIZEHINT: $sizehint\n"; + $tex = $1; + $stub = make_stub($tex, $sizehint); + $line =~ s/(\$.*?\$)(\((\d+)\))?/\"$stub\"/; + print TEXOUT "\\psfrag{$stub}[cc][cc]{$tex}\n"; + } +# print "FINAL LINE: $line"; + print $dotout $line; + } + + close($dotout); + close(TEXOUT); + +# print STDERR "dot -Tps $dotoutFilename > $filenameBase.ps"; + system("$graphProgramName -Tps $dotoutFilename > $filenameBase.ps"); + +} + +sub make_stub($$) +{ + # Make a placeholder (stub) for the TeX which will be substituted for the + # real formatted TeX later. This is tricky because the length of the stub + # that we choose affects how Dot formats the PostScript. We use the + # heuristic that the length of the LaTeX code is correlated with the + # amount of space needed to render the LaTeX code. + + if ($paststubs{$_[0]}) { + return $paststubs{$_[0]}; + } + + my $length = int($_[1]); + if ($length == 0) { + # no sizehint given + $length = sqrt(length($_[0])); + } +# print "LENGTH of $_[0]: $length\n"; + $stub_charset="-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + my $stub = ""; + for (my $i = 1; $i <= $length; $i++) { + $stub .= substr($stub_charset, int(rand(length($stub_charset))), 1); + #$stub = $stub . int(rand(length($stub_charset))); + } + #print "NEW STUB for $_[0]: $stub\n"; + $paststubs{$_[0]} = $stub; + return $stub; + } + + diff --git a/support/easylatex/easylatex/transforms/90numberSign.pl b/support/easylatex/easylatex/transforms/90numberSign.pl new file mode 100755 index 0000000000..eed7018be0 --- /dev/null +++ b/support/easylatex/easylatex/transforms/90numberSign.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl -i.bak + +use English; + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +$file =~ s/#/\\#/g; + +print $file; + diff --git a/support/easylatex/easylatex/transforms/90removeWhitespaceAroundEquations.pl b/support/easylatex/easylatex/transforms/90removeWhitespaceAroundEquations.pl new file mode 100755 index 0000000000..80370df0d4 --- /dev/null +++ b/support/easylatex/easylatex/transforms/90removeWhitespaceAroundEquations.pl @@ -0,0 +1,13 @@ +#!/usr/bin/perl -i.bak + +use English; + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +$file =~ s/\n\\begin{align\*}/\\begin{align\*}/g; + + +print $file; + diff --git a/support/easylatex/easylatex/transforms/91easyQuotes.pl b/support/easylatex/easylatex/transforms/91easyQuotes.pl new file mode 100755 index 0000000000..6c602830db --- /dev/null +++ b/support/easylatex/easylatex/transforms/91easyQuotes.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl -i.bak + +#print STDERR "\n\n\n\n\n************I SAID:\n$file\n\n\n\n\n\n"; + +use English; + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +$file =~ s/(?<!\\)"(.+?(?<!\\))"/``\1''/g; +#$file =~ s/"(.+?)"/``\1''/g; + + + +print $file; + diff --git a/support/easylatex/easylatex/transforms/91easySections.pl b/support/easylatex/easylatex/transforms/91easySections.pl new file mode 100755 index 0000000000..78dbfae5f9 --- /dev/null +++ b/support/easylatex/easylatex/transforms/91easySections.pl @@ -0,0 +1,106 @@ +#!/usr/bin/perl -i.bak + +use English; + +use vars qw($EASYLATEXSTORE_RESERVED_WORD @MATH_MODE_SYMBOLS $MATH_MODE_SYMBOL_FILEPATH); + +$EASYLATEXSTORE_RESERVED_WORD = 'EASYLATEXSTORE'; +use vars qw($StorageIndex @Stored); + +$StorageIndex = 0; + + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +## transform it + +$file = storeMathModes($file); + +if (($file =~ /\\documentclass(\[[^\]]*\])?{article}/) || ($file =~ /\\documentclass(\[[^\]]*\])?{report}/) ) +{ + $file =~ s/^====(.*)====\s*$/\\subsubsection*{$1}/mg; + $file =~ s/^===(.*)===\s*$/\\subsection*{$1}/mg; + $file =~ s/^==(.*)==\s*$/\\section*{$1}/mg; +} +elsif ($file =~ /\\documentclass(\[[^\]]*\])?{seminar}/) +{ + $file =~ s/^=======(.*)=======\s*$/\\begin{scriptsize}$1\\end{scriptsize}/mg; + $file =~ s/^=====(.*)=====\s*$/\\begin{small}$1\\end{small}/mg; + $file =~ s/^====(.*)====\s*$/\\textbf{$1}/mg; + $file =~ s/^===(.*)===\s*$/\\slidesubheading{$1}/mg; + $file =~ s/^==(.*)==\s*$/\\slideheading{$1}/mg; + + $file =~ s/^---$/\\smallskip\\hrulefill\\smallskip/mg; +} +elsif ($file =~ /\\documentclass(\[[^\]]*\])?{prosper}/) +{ + $file =~ s/^=======(.*)=======\s*$/\\begin{scriptsize}$1\\end{scriptsize}/mg; + $file =~ s/^=====(.*)=====\s*$/\\begin{small}$1\\end{small}/mg; + $file =~ s/^====(.*)====\s*$/\\textbf{$1}/mg; + $file =~ s/^===(.*)===\s*$/\\begin{large}$1\\end{large}/mg; + $file =~ s/^==(.*)==\s*$/\\begin{huge}$1\\end{huge}/mg; + + $file =~ s/^---$/\\smallskip\\hrulefill\\smallskip/mg; +} +else { + $file =~ s/^====(.*)====\s*$/\\subsubsection*{$1}/mg; + $file =~ s/^===(.*)===\s*$/\\subsection*{$1}/mg; + $file =~ s/^==(.*)==\s*$/\\section*{$1}/mg; +} + + +$file = unstoreMathModes($file); + +# print output +print $file; + + +###################### +# "store" subroutines +###################### + +sub storeMathModes { + my ($file) = @_; + + ${notSlashRE_begin} = '(^|(?!\\).)'; + ${notSlashRE} = '(?!\\).'; + + $file =~ s/(\\begin{align}.*?\\end{align})/store($1)/egs; + $file =~ s/(\\begin{align\*}.*?\\end{align\*})/store($1)/egs; + $file =~ s/(\\begin{eqnarray}.*?\\end{eqnarray})/store($1)/egs; + $file =~ s/(\\begin{eqnarray\*}.*?\\end{eqnarray\*})/store($1)/egs; + $file =~ s/(\\begin{equation}.*?\\end{equation})/store($1)/egs; + $file =~ s/(\\begin{equation\*}.*?\\end{equation\*})/store($1)/egs; + + $file =~ s/((?<!\\)\$.*?(?<!\\)\$)/store($1)/egs; + + return $file; +} + +sub unstoreMathModes { + my ($file) = @_; + +# print STDERR "UNSTORE:\n\n".$file; + + while ($file =~ s/${EASYLATEXSTORE_RESERVED_WORD}_(\d+)_${EASYLATEXSTORE_RESERVED_WORD}/$Stored{$1}/egs) {} + + return $file; +} + + + +sub store { + # got this idea from UseMod + my ($toBeStored) = @_; + + $Stored{$StorageIndex} = $toBeStored; +# print STDERR "STORED: $toBeStored\n"; + +# print STDERR "REPLACEDW: ".${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex . '_'.${EASYLATEXSTORE_RESERVED_WORD}; + + return ${EASYLATEXSTORE_RESERVED_WORD}.'_' . $StorageIndex++ . '_'.${EASYLATEXSTORE_RESERVED_WORD}; +} + + diff --git a/support/easylatex/easylatex/transforms/91seminarAddSlidesec.pl b/support/easylatex/easylatex/transforms/91seminarAddSlidesec.pl new file mode 100755 index 0000000000..8a9e5a73be --- /dev/null +++ b/support/easylatex/easylatex/transforms/91seminarAddSlidesec.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl -i.bak + +use English; + + +###################### +# DEFINE GLOBAL CONSTANTS +###################### +@usepackage_list = qw(slidesec); + +###################### +# BEGIN MAIN +###################### + + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR "*********** I got: $file\n"; + + +if ($file =~ /\\documentclass{seminar}/) +{ + + foreach $pkg (@usepackage_list) { + if (!( $file =~ /\\usepackage(\[[^\]]*\])?{$pkg}/ )) + { + $file =~ s/\\begin{document}/\\usepackage{$pkg} % pkg required by EasyLatex\n\\begin{document}/; + # + } + } +} + + + +print $file; diff --git a/support/easylatex/easylatex/transforms/91seminarEnvAddSlide.pl b/support/easylatex/easylatex/transforms/91seminarEnvAddSlide.pl new file mode 100755 index 0000000000..0dda922be1 --- /dev/null +++ b/support/easylatex/easylatex/transforms/91seminarEnvAddSlide.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl -i.bak + +use English; + + +###################### +# DEFINE GLOBAL CONSTANTS +###################### + + +###################### +# BEGIN MAIN +###################### + + + +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR "*****************I got: $file\n"; + +if ($file =~ /\\documentclass{(seminar|prosper)}/) +{ + if (!($file =~ /\\begin{slide\*?}/)) + { + $file =~ s/\\begin{document}/\\begin{document}\n\\begin{slide}/i; + $file =~ s/\\end{document}/\\end{slide}\n\\end{document}/i; + $file =~ s/^----\n/\\end{slide}\n\\begin{slide}\n/mg; + } + + + +} + + +print $file; diff --git a/support/easylatex/easylatex/transforms/92seminarFlushHeadingsTop.pl b/support/easylatex/easylatex/transforms/92seminarFlushHeadingsTop.pl new file mode 100755 index 0000000000..931b6aa5c1 --- /dev/null +++ b/support/easylatex/easylatex/transforms/92seminarFlushHeadingsTop.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR $file; + +## transform it + +if ($file =~ /\\documentclass(\[[^\]]*\])?{seminar}/ + && + $file =~ /\\flushheadingstop/) +{ + $file =~ s/\\flushheadingstop//g; + $file =~ s/(\\begin{slide}\s*)(\\slideheading{.*?}.*?)(\\end{slide})/$1 . processSlide($2) . $3/egs; +} + + + +# print output +print $file; + + + +sub processSlide { + ($slide) = @_; + +# print STDERR "Got slide: $slide\n"; + + if ($slide =~ /((?:\\slideheading{[^\n]+}\s*)+)(.*)/s) { + return "$1\n" . '\vspace*{\fill}' . "\n" . "$2\n" . '\vspace*{\fill}' . "\n"; + } + + else { + return $slide; + } +} diff --git a/support/easylatex/easylatex/transforms/92tempKludges.pl b/support/easylatex/easylatex/transforms/92tempKludges.pl new file mode 100644 index 0000000000..deec8d8326 --- /dev/null +++ b/support/easylatex/easylatex/transforms/92tempKludges.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl -i.bak + +use English; + +## get input +undef $INPUT_RECORD_SEPARATOR; +$file = <>; + +#print STDERR "*********** I got: $file\n"; + +## transform it + +#$file =~ s/\$\\mathbb{R}\$\^(.))/\$mathbb{R}^$1\$/g; +#$file =~ s/\$\\mathbb{R}\$\^(.))/hi/g; + +# print output +print $file |