Saturday, March 15, 2008

note2latex

Back when I was at Cascadia, I had decided to take my notes in LaTeX. However, I soon realized that pure LaTeX wouldn't do, as it was a bit too generic for my purposes. In order to reduce the load, I wrote a couple of scripts (unnecessary to use two, but I felt like it) and a style file.

note2latex

#!/bin/bash
TEXPP=/usr/local/bin/texpp.pl
LATEX=/usr/bin/latex

JOBNAME="$1.out"
OUT="$JOBNAME.tex"
$TEXPP "$1" "$OUT"
$LATEX "$OUT"
if [[ "`grep -i '\\\label' "$OUT" 2> /dev/null`" != "" || "`grep -i '\\\ref' "$OUT" 2> /dev/null`" != "" ]]; then
$LATEX "$OUT"
fi
rm -f "$OUT"
mv -f "$JOBNAME.dvi" "`basename "$1" .tex`.dvi"
mv -f "$JOBNAME.aux" "`basename "$1" .tex`.aux"
mv -f "$JOBNAME.log" "`basename "$1" .tex`.log"

texpp.pl

#!/usr/bin/perl
use strict;
use utf8;
scalar @ARGV >= 2 || die "No file given.\nUsage: texpp.pl infile outfile.\n";
my $infile = $ARGV[0];
my $outfile = $ARGV[1];
-e "$infile" || die "No such file.\n";
open(BUFF, "$infile") || die "Input file opening error.";
my @lines = <BUFF>;
close(BUFF);
my $count = scalar @lines;
for(my $i = 0; $i < $count; $i++) {
$lines[$i] =~ s/\\begin{sls}{([A-z]*)}/\\begin{sls}{\1}{foo$i}/g;
}
my @outlines = ("\\documentclass[12pt,letterpaper]{article}\n", "\\usepackage{notes}\n", "\\usepackage[margin=0.5in]{geometry}\n", "\\pagestyle{empty}\n", "\\begin{document}\n", @lines, "\\end{document}\n");
open(BUFF, ">$outfile") || die "Output file opening error.";
print BUFF @outlines;
close(BUFF);

notes.sty

\ProvidesPackage{notes}[2007/01/03 note list formatter]
\usepackage[dvips]{graphicx}
\usepackage{wrapfig}
\usepackage{color}
\usepackage{polynom}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{amsfonts}
\polyset{vars=}
\newenvironment{note}[2]{
\hfill \emph{`` #1''}

\hfill #2

}
{
\par
}
\newenvironment{sls}[2]{
\newcounter{#2}\begin{list}{\csname#1\endcsname{#2}.}{\usecounter{#2}}
}
{
\end{list}\par
}
\newcommand{\dm}[1]{$\displaystyle #1$}
\newcommand{\im}[1]{\item $\displaystyle #1$}
\newcommand{\Sum}{
\displaystyle\sum
}
\newcommand{\Lim}{
\displaystyle\lim
}
\newcommand{\Int}{
\displaystyle\int
}
\newcommand{\laplace}{\mathscr{L}}
\newcommand{\ns}{\mathscr{N}}
\newcommand{\rng}{\mathscr{R}}
\newcommand{\s}{\mathbb{S}}
\renewcommand{\choose}[2]{\left(\begin{array}{c}
#1 \\
#2 \\
\end{array}\right)}
\newcommand{\rsp}{\mbox{Row}}
\newcommand{\csp}{\mbox{Col}}
\newcommand{\real}{\mathbb{R}}
\newcommand{\complex}{\mathbb{C}}
\newcommand{\rational}{\mathbb{Q}}
\newcommand{\To}{$\to$\hspace{4pt}}
\newcommand{\E}[1]{\times 10^{#1}}
\newcommand{\diff}[2]{\frac{d #1}{d #2}}
\newcommand{\pdiff}[2]{\displaystyle\frac{\partial #1}{\partial #2}}
\newcommand{\degree}{^\circ}
\newcommand{\tdot}{$\cdot$}
\newcommand{\then}{\mbox{then}}
\newcommand{\lvb}{\left <}
\newcommand{\rvb}{\right >}
\newcommand{\pvec}[1]{\left < #1\right >}
\newcommand{\lb}{\left [}
\newcommand{\rb}{\right ]}
\newcommand{\pbs}[1]{\left [ #1\right ]}
\newcommand{\bbs}[1]{\Big [ #1\Big ]}
\newcommand{\lp}{\left (}
\newcommand{\rp}{\right )}
\newcommand{\pcs}[1]{\left \{ #1\right \}}
\newcommand{\pps}[1]{\left ( #1\right )}
\newcommand{\abs}[1]{\left |#1\right |}
\newcommand{\vlen}[1]{\left \|#1\right \|}
\newcommand{\eval}[2]{\Big |_{#1}^{#2}}
\newcommand{\spn}[1]{\mbox{span}\pcs{#1}}
\newcommand{\spp}[1]{\mbox{span}}
\newcommand{\bol}[1]{\textbf{#1}}
\newcommand{\ita}[1]{\textit{#1}}
\newcommand{\und}[1]{\underline{#1}}
%\newcommand{\iint}{\int\!\!\!\int}
%\newcommand{\iiint}{\int\!\!\!\int\!\!\!\int}
\newcommand{\blue}[1]{\begin{color}{blue}#1\end{color}}
\newcommand{\green}[1]{\begin{color}{green}#1\end{color}}
\newcommand{\red}[1]{\begin{color}{red}#1\end{color}}
\newcommand{\cyan}[1]{\begin{color}{cyan}#1\end{color}}


\newcommand{\ihat}{\hat\imath}
\newcommand{\jhat}{\hat\jmath}
\newcommand{\khat}{\hat k}


\newcommand{\Sup}[1]{$\displaystyle ^{\mbox{\tiny #1}}$}
\newcommand{\Sub}[1]{$\displaystyle _{\mbox{\tiny #1}}$}
\renewenvironment{matrix}[1]{\left [\begin{array}{ #1}}
{\end{array}\right ]}
\newenvironment{varr}{\left [\begin{array}{c}}
{\end{array}\right ]}
\newenvironment{detr}[1]{\left |\begin{array}{ #1}}
{\end{array}\right |}
\newenvironment{forty}{T\left (\left [\begin{array}{c}}
{\end{array}\right ]\right )}
\newcommand{\pldv}[4]{\polyset{vars=#1}\polylongdiv[stage=#2]{#3}{#4}\polyset{vars=}}
\newcommand{\syndev}[5]{\begin{array}{r | #2}
#1 & #3 \\
&&#4 \\
\hline
& #5 \\
\end{array}}

No comments: