~mwshinn/+junk/notes

« back to all changes in this revision

Viewing changes to latexify-notes.pl.n

  • Committer: Max Shinn
  • Date: 2014-10-17 18:35:47 UTC
  • mfrom: (42.1.3 notes-bin)
  • Revision ID: trombonechamp@gmail.com-20141017183547-8n5g1g1uywdwiiym
Merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
352
352
 
353
353
Simplified LaTeX is preprocessor for LaTeX math mode.  It is designed
354
354
to make LaTeX math more readable in text format, easier to type, and
355
 
display nicer.
 
355
display nicer.  The most prominant feature is UTF-8 support for (most)
 
356
mathematical symbols.  
356
357
 
357
358
- Brackets can be entered by including brackets with spaces on both
358
359
  sides, such as "A = { 1 2 3 } ⊂ ℝ".  They may also be entered in the
383
384
"[1 2 3; 4 \sqrt{5} 6; sin(x^2)+7 8 9]" will be typeset as
384
385
$mat[1 2 3; 4 \sqrt{5} 6; sin(x^2)+7 8 9]$.
385
386
 
 
387
*** Exponents and subscripts
 
388
 
 
389
Exponents and subscripts do not have to be enclosed in brackets if
 
390
they consist only of alphanumeric characters.  Optionally, they may
 
391
begin with a negative sign.  This can be broken with a space.
 
392
 
 
393
*** Quotes
 
394
 
 
395
Double quotes within a math environment will display the enclosed text
 
396
raw with a roman font.  This is especially useful for proofs (when
 
397
used with alignment) and sub/super-scripted variable names.
 
398
 
 
399
*** Brackets
 
400
 
 
401
Brackets will be interpreted as literals when surrounded by spaces.
 
402
 
386
403
** Links, labels, and captions
387
404
 
388
405
** Extracting code
629
646
           "acos", "atan", "sec", "csc", "cot", "ln", "log", "max",
630
647
           "min", "sup", "inf", "ker", "coker", "rng", "corng", "var",
631
648
           "rank", "rk", "exp", "erf", "det", "tr", "lim", "Cov",
632
 
           "Var", "Bias", "floor", "ceil", "Re", "Im");
 
649
           "Var", "Bias", "floor", "ceil", "Re", "Im", "Median");
633
650
 
634
651
%replacements = (
635
652
    "\\.\\.\\." => "\\ldots ",
1101
1118
    my $imgfile = create_absolute_link(${$tree}{Image}{line});
1102
1119
    my $text = "\\begin{center}\n";
1103
1120
    my $label = "";
1104
 
    $text .= "\\includegraphicsscaled{$imgfile}\n";
 
1121
    # Allow .tex files to be treated as images
 
1122
    do { 
 
1123
        no Regexp::Grammars;
 
1124
        if ($imgfile =~ /\.tex$/) {
 
1125
            $text .= "\\input{$imgfile}\n";
 
1126
        }
 
1127
        else {
 
1128
            $text .= "\\includegraphicsscaled{$imgfile}\n";
 
1129
        }
 
1130
    };
1105
1131
    $text .= "\\end{center}\n";
1106
1132
 
1107
1133
    if (exists $tree->{Image}->{optionallabel}) {
1127
1153
    my $text = ${$tree}{InlineMath}{mathtext};
1128
1154
    $text = utf8_substitute($text, 1);
1129
1155
    $text = math_formatting($text);
 
1156
    do { # Fix equations going across margin problem
 
1157
        no Regexp::Grammars;
 
1158
        $text =~ s/ = / =\\allowbreak /g;
 
1159
    };
1130
1160
    return '$' . $text . '$';
1131
1161
}
1132
1162
sub proc_quotes {
1141
1171
    my $text = ${$tree}{Feedback}{feedbacktext};
1142
1172
    $text = escape_latex($text);
1143
1173
    $text = utf8_substitute($text, 0);
 
1174
    $text = text_substitute($text);
1144
1175
    if ($properties{'Type'} eq "Draft") {
1145
1176
        return "\\todo[fancyline,size=\\tiny]{$text}";
1146
1177
    }
1498
1529
        "gnuplot" => "Gnuplot",
1499
1530
        "sh" => "sh",
1500
1531
        "erl" => "erlang",
1501
 
        "el" => "Lisp"
 
1532
        "el" => "Lisp",
 
1533
        "r" => "R"
1502
1534
    );
1503
1535
    
1504
1536
    my $text = "";
1826
1858
\\DeclareMathOperator{\\Bias}{Bias}
1827
1859
\\DeclareMathOperator{\\floor}{floor}
1828
1860
\\DeclareMathOperator{\\ceil}{ceil}
 
1861
\\DeclareMathOperator{\\Median}{Median}
1829
1862
 
1830
1863
% Augmented matrices
1831
1864
\\makeatletter
2017
2050
$path = (fileparse($filename))[1];
2018
2051
<===
2019
2052
 
 
2053
If there is a directory for the note file, export the scripts to there
 
2054
in a subdiretory called "generated-scripts".  If not, export it to the
 
2055
same directory as the note file.
 
2056
 
 
2057
===>
 
2058
$prefix = "$path";
 
2059
if (-d "$filename.d") {
 
2060
    $prefix = "$filename.d/generated-scripts/";
 
2061
    mkdir $prefix;
 
2062
}
 
2063
<===
 
2064
 
2020
2065
The second optional command line parameter allows you to specify one
2021
2066
of the source files to be displayed as output.  Even if it is
2022
2067
displayed as output, it will still be written to the correct file.
2102
2147
 
2103
2148
===>
2104
2149
while(($k,$v)=each(%sourcetexts)) {
2105
 
    open HANDLE, ">",  $path . "/" . $k;
 
2150
    open HANDLE, ">",  "$prefix$k";
2106
2151
    print HANDLE $v;
2107
2152
    close HANDLE;
2108
2153
    if ($onlyshow eq $k) {