~mszamot-gmail/automatictexplugin/atp-vim

« back to all changes in this revision

Viewing changes to ftplugin/ATP_files/latex_log.py

  • Committer: mszamotulski
  • Date: 2012-04-27 10:21:38 UTC
  • Revision ID: svn-v4:0f6a0787-2b0d-4cb9-afe4-9962f7273948:trunk:413
Version 11 (first commit).
Small changes in .py scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
 
3
 
# Todo: should be '\hbox ... too wide.' (add '\hbox to the message).
4
 
 
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# Usage: latex_log.py {tex_log_file}
 
5
# Produces a "._log" file.
5
6
 
6
7
# Author: Marcin Szamotulski
7
8
# http://atp-vim.sourceforge.net
22
23
#     You should have received a copy of the GNU General Public License along
23
24
#     with Automatic Tex Plugin for Vim.  If not, see <http://www.gnu.org/licenses/>.
24
25
 
25
 
# Info: this is a python script which reads latex log fiele (which path is gven
26
 
# as the only argument) and it writes back a log messages which are in the
 
26
# INFO: 
 
27
# This is a python script which reads latex log file (which path is gven as
 
28
# the only argument) and it writes back a log messages which are in the
27
29
# following format:
28
30
# WARNING_TYPE::FILE::INPUT_LINE::INPUT_COL::MESSAGE (ADDITIONAL_INFO)
29
31
# this was intendent to be used for vim quick fix:
30
32
# set errorformat=LaTeX\ %tarning::%f::%l::%c::%m,Citation\ %tarning::%f::%l::%c::%m,Reference\ %tarning::%f::%l::%c::%m,Package\ %tarning::%f::%l::%c::%m,hbox\ %tarning::%f::%l::%c::%m,LaTeX\ %tnfo::%f::%l::%c::%m,LaTeX\ %trror::%f::%l::%c::%m
 
33
#
31
34
# The fowllowing WARNING_TYPEs are available:
32
35
# LaTeX Warning
33
36
# Citation Warning
42
45
# Input Package                 : includes packges and document class
43
46
 
44
47
# Note: when FILE,INPUT_LINE,INPUT_COL doesn't exists 0 is put.
45
 
# for Input Package FILE is 0.
46
 
 
47
48
 
48
49
# It will work well when the tex file was compiled with a big value of 
49
50
# max_print_line (for example with `max_print_line=2000 latex file.tex')
56
57
import sys, re, os, os.path, fnmatch
57
58
 
58
59
def shift_dict( dictionary, nr ):
59
 
# add nr to every value of dictionary
 
60
    ''' Add nr to every value of dictionary.
60
61
 
61
 
    for key in dictionary.keys():
 
62
    '''
 
63
    for key in dictionary.iterkeys():
62
64
        dictionary[key]+=nr
63
65
    return dictionary
64
66
 
69
71
    # option the files under project_tmpdir will be written using project_dir
70
72
    # (this is for the aux file).
71
73
 
72
 
    if output_fname == None:
 
74
    if output_fname is None:
73
75
        output_fname = os.path.splitext(input_fname)[0]+"._log"
74
76
 
75
77
    try:
150
152
    package_info_pat = re.compile('Package (\w+) Info: ')
151
153
    package_info = "Package Info"
152
154
 
153
 
    hbox_info_pat = re.compile('(Over|Under)full \\\\hbox')
 
155
    hbox_info_pat = re.compile('(Over|Under)full \\\\hbox ')
154
156
    hbox_info = "hbox Warning"
155
157
 
156
158
    latex_info_pat = re.compile('LaTeX Info: ')
319
321
                    output_data.append([package_info, last_file, "0", "0", msg+" ("+package+")"])
320
322
            elif re.match(hbox_info_pat, line):
321
323
                # Log Message: '(Over|Under)full \\\\hbox'
322
 
                input_line = re.search('at lines (\d+)--(\d+)', line)
 
324
                input_line = re.search('at lines? (\d+)(?:--(?:\d+))?', line)
323
325
                if re.match('Underfull', line):
324
326
                    h_type = 'Underfull '
325
327
                else:
326
328
                    h_type = 'Overfull '
327
 
                msg = h_type+'\\hbox '+re.search('\((.*)\)', str(re.sub(hbox_info_pat,'', line))).group(1)
 
329
                msg = h_type+'\\hbox '+str(re.sub(hbox_info_pat, '', line))
328
330
                if msg == "":
329
331
                    msg = " "
330
332
                if input_line:
388
390
                        nline = log_lines[line_nr-1+i]
389
391
                        line_m = re.match('l\.(\d+) (.*)', nline)
390
392
                        if line_m:
391
 
                            if input_line == None:
 
393
                            if input_line is None:
392
394
                                input_line = line_m.group(1)
393
395
                            rest = line_m.group(2)+re.sub('^\s*', ' ', log_lines[line_nr+i])
394
396
                            break
395
397
                        elif i>50:
396
 
                            if input_line == None:
 
398
                            if input_line is None:
397
399
                                input_line="0"
398
400
                            rest = ""
399
401
                            break
400
402
                    except IndexError:
401
 
                        if input_line == None:
 
403
                        if input_line is None:
402
404
                            input_line="0"
403
405
                        rest = ""
404
406
                        break