ó x”þfc@sœdZddlZddlZddlZddlmZmZmZddlZdZ d„Z gd„Z dd„Z edkr˜eje ƒƒ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. iÿÿÿÿN(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||gƒkrYdSd||||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}xÀtt |ƒt ||dd/ƒƒD]™\}}|j ƒ}xû| j |ƒD]ê\}}}d|kr´|GdG|G|G|Gn|dkrâd|krâ| j||fƒnr||kr| j||fƒnP|dkr2d|kr2t||| |ƒn"||krTt||| |ƒnd|kr‚dG| GHq‚q‚Wxv| j |ƒD]e\}}|dkr¨|j|ƒn|dkr€y|jƒWqåtk rád|fGHqåXq€q€Wd|krûqZnxW|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]$}||krëd&||fGHqëqëW|j|ƒ}|r@|jdƒ}|}n|j|ƒ}|r‹|jdƒ|kr‹d'|jdƒ|||fGHn|j|ƒr£d}nd(|ks»d)|krÊd*|fGHnx&| j |ƒD]} d+| |fGHqÚWqZW|}!x#| D]\}}"d,|"|fGHqWx|D]}d-|fGHq*Wd.|!fGHdS(0s¼Check 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 \newcommandiÿÿÿÿs(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|ks­d|kr‰tj|ƒ|||d+q‰q‰Wg|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.pytmainÄs6  !+     t__main__(RPRRLRNt itertoolsRRRRSRR RGR R`t__name__texit(((s./usr/lib64/python2.7/Tools/scripts/texcheck.pyts     z $