fc@sdZddlZddlZddlZddlmZmZmZddlZdZ dZ gdZ ddZ edkreje ndS( s TeXcheck.py -- rough syntax checking on Python style LaTeX documents. Written by Raymond D. Hettinger Copyright (c) 2003 Python Software Foundation. All rights reserved. Designed to catch common markup errors including: * Unbalanced or mismatched parenthesis, brackets, and braces. * Unbalanced or mismatched \begin and \end blocks. * Misspelled or invalid LaTeX commands. * Use of forward slashes instead of backslashes for commands. * Table line size mismatches. Sample command line usage: python texcheck.py -k chapterheading -m lib/librandomtex *.tex Options: -m Munge parenthesis and brackets. [0,n) would normally mismatch. -k keyword: Keyword is a valid LaTeX command. Do not include the backslash. -d: Delimiter check only (useful for non-LaTeX files). -h: Help -s lineno: Start at lineno (useful for skipping complex sections). -v: Verbose. Trace the matching of //begin and //end blocks. iN(tiziptcounttislices \section \module \declaremodule \modulesynopsis \moduleauthor \sectionauthor \versionadded \code \class \method \begin \optional \var \ref \end \subsection \lineiii \hline \label \indexii \textrm \ldots \keyword \stindex \index \item \note \withsubitem \ttindex \footnote \citetitle \samp \opindex \noindent \exception \strong \dfn \ctype \obindex \character \indexiii \function \bifuncindex \refmodule \refbimodindex \subsubsection \nodename \member \chapter \emph \ASCII \UNIX \regexp \program \production \token \productioncont \term \grammartoken \lineii \seemodule \file \EOF \documentclass \usepackage \title \input \maketitle \ifhtml \fi \url \Cpp \tableofcontents \kbd \programopt \envvar \refstmodindex \cfunction \constant \NULL \moreargs \cfuncline \cdata \textasciicircum \n \ABC \setindexsubitem \versionchanged \deprecated \seetext \newcommand \POSIX \pep \warning \rfc \verbatiminput \methodline \textgreater \seetitle \lineiv \funclineni \ulink \manpage \funcline \dataline \unspecified \textbackslash \mimetype \mailheader \seepep \textunderscore \longprogramopt \infinity \plusminus \shortversion \version \refmodindex \seerfc \makeindex \makemodindex \renewcommand \indexname \appendix \protect \indexiv \mbox \textasciitilde \platform \seeurl \leftmargin \labelwidth \localmoduletable \LaTeX \copyright \memberline \backslash \pi \centerline \caption \vspace \textwidth \menuselection \textless \makevar \csimplemacro \menuselection \bfcode \sub \release \email \kwindex \refexmodindex \filenq \e \menuselection \exindex \linev \newsgroup \verbatim \setshortversion \author \authoraddress \paragraph \subparagraph \cmemberline \textbar \C \seelink cCsry|j\}}Wn!tk r9d||fGHdSX||j||gkrYdSd||||fGHdS(sCVerify that closing delimiter matches most recent opening delimitersU Delimiter mismatch. On line %d, encountered closing '%s' without corresponding openNsJ Opener '%s' on line %d was not closed before encountering '%s' on line %d(tpopt IndexErrortget(tc_linenotc_symboltopenerstpairmapto_linenoto_symbol((s./usr/lib64/python2.7/Tools/scripts/texcheck.pyt matchclose?s c#CsPtjd}tjd}ttj}x|D]}|jd|q7Wd|kruidd6dd6}nid d6d d6}td}tjd } tjd } tjd } tjd} g} g}tjd}tjd}tjd}d}d}t|jdd}d}xtt |t ||dd/D]\}}|j }x| j |D]\}}}d|kr|GdG|G|G|Gn|dkrd|kr| j||fnr||kr| j||fnP|dkr2d|kr2t||| |n"||krTt||| |nd|krdG| GHqqWxv| j |D]e\}}|dkr|j|n|dkry|jWqtk rd|fGHqXqqWd|krqZnxW|j |D]F}d |ks d!|kr/q nd||kr d"||fGHq q Wx)| j |D]}d#|||fGHqeW|jd$}|d%kr|jd|}|jd|}|j||d|!nx5|j |D]$}||krd&||fGHqqW|j|}|r@|jd}|}n|j|}|r|jd|krd'|jd|||fGHn|j|rd}nd(|ksd)|krd*|fGHnx&| j |D]} d+| |fGHqWqZW|}!x#| D]\}}"d,|"|fGHqWx|D]}d-|fGHq*Wd.|!fGHdS(0sCheck the LaTeX formatting in a sequence of lines. Opts is a mapping of options to option values if any: -m munge parenthesis and brackets -d delimiters only checking -v verbose trace of delimiter matching -s lineno: linenumber to start scan (default is 1). Morecmds is a sequence of LaTeX commands (without backslashes) that are to be considered valid in the scan. s \\[A-Za-z]+s \/([A-Za-z]+)s\s-ms[(t]s([t)t[t(s&\\(begin|end){([_a-zA-Z]+)}|([()\[\]])s({)|(})s(\b[A-za-z]+\b) \b\1\bs<\\(ABC|ASCII|C|Cpp|EOF|infinity|NULL|plusminus|POSIX|UNIX)\ss\\begin{(?:long)?table([iv]+)}s\\line([iv]+){s\\end{(?:long)?table([iv]+)}tis-st1is-vt|tbegins-dtends --> t{t}s Warning, unmatched } on line %s.t822s.htmls4Warning, forward slash used on line %d with cmd: /%ss2Warning, \%s should be written as \%s{} on line %ds \newcommandis(Warning, unknown tex cmd on line %d: \%ss>Warning, \line%s on line %d does not match \table%s on line %dse.g.si.e.s2Style warning, avoid use of i.e or e.g. on line %ds&Doubled word warning. "%s" on line %ds(Unmatched open delimiter '%s' on line %dsUnmatched { on line %dsDone checking %d lines.N(tretcompiletsettcmdstrtsplittaddtintRRRRtNonetrstriptfindalltappendR RRtfindtsearchtgroup(#tsourcetoptstmorecmdsttexcmdt falsetexcmdt validcmdstcmdR t openpunctt delimiterstbracest doubledwordst spacingmarkupRt bracestackt tablestartt tablelinettableendt tablelevelttablestartlinet startlinetlinenotlinetbegendtnametpuncttopentclosetnctstartRtmtdwtlastlinetsymbol((s./usr/lib64/python2.7/Tools/scripts/texcheck.pytcheckitJs    2            !   c Cs|dkrtjd}ntj|d\}}t|}d|ksX|gkratGHdSt|dkr|dGHdSxOt|D]A\}}d|ksd|krtj||||d+qqWg|D]\}}|dkr|^q}g} x}|D]u} d d GHd G| GHyt | } Wnt k rOd |dGHd SXz| j t | ||Wd| j XqWt| S(Nisk:mdhs:vs-his#Please specify a file to be checkedt*t?s-kt=itCheckingsCannot open file %s.i(R tsystargvtgetopttdictt__doc__tlent enumeratetglobR?tIOErrorR#RGR@tmax( targstoptitemstarglistR(titfilespectktvR)terrtfilenametf((s./usr/lib64/python2.7/Tools/scripts/texcheck.pytmains6  !+     t__main__(RPRRLRNt itertoolsRRRRSRR RGR R`t__name__texit(((s./usr/lib64/python2.7/Tools/scripts/texcheck.pyts     z $