rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
sys.stderr.write("%s, %s, %s %s\n" %(val[0],val[1],val[2],lines[i]))
def table_update(lines): lines[1] = string.replace(lines[1], '<Features', '<features') res = features_re.match( lines[1] ) if res: val = res.groups() lines[1] = '<features rotate="%s" islongtable="%s" endhead="%s" endfirsthead="%s" endfoot="%s" endlastfoot="%s">' % (bool_table[val[0]], bool_table[val[1]], val[2], val[3...
ert_rexp = re.compile(r"\\begin_inset|.*\\SpecialChar")
ert_rexp = re.compile(r"\\begin_inset|\\hfill|.*\\SpecialChar")
def is_empty(lines): return filter(is_nonempty_line, lines) == []
inset = specialchar = 0
inset = hfill = specialchar = 0
def remove_oldert(lines): i = 0 while 1: i = find_tokens(lines, ["\\latex latex", "\\layout LaTeX"], i) if i == -1: break j = i+1 while 1: # \end_inset is for ert inside a tabular cell. The other tokens # are obvious. j = find_tokens(lines, ["\\latex default", "\\layout", "\\begin_inset", "\\end_inset", "\\end_float", ...
i = insert_ert(file.body, i, 'Collapsed', ert, file.format + 1)
i = insert_ert(file.body, i, 'Collapsed', ert, file.format - 1)
def convert_frameless_box(file): pos = ['t', 'c', 'b'] inner_pos = ['c', 't', 'b', 's'] i = 0 while 1: i = find_token(file.body, '\\begin_inset Frameless', i) if i == -1: return j = find_end_of_inset(file.body, i) if j == -1: file.warning("Malformed LyX file: Missing '\\end_inset'.") i = i + 1 continue del file.body[i]...
j = insert_ert(file.body, j, 'Collapsed', ert, file.format + 1)
j = insert_ert(file.body, j, 'Collapsed', ert, file.format - 1)
def convert_frameless_box(file): pos = ['t', 'c', 'b'] inner_pos = ['c', 't', 'b', 's'] i = 0 while 1: i = find_token(file.body, '\\begin_inset Frameless', i) if i == -1: return j = find_end_of_inset(file.body, i) if j == -1: file.warning("Malformed LyX file: Missing '\\end_inset'.") i = i + 1 continue del file.body[i]...
Declear line are like this: (article.layout, scrbook.layout, svjog.layout)
Declare lines look like this: (article.layout, scrbook.layout, svjog.layout)
def processLayoutFile(file, bool_docbook, bool_linuxdoc): ''' process layout file and get a line of result Declear line are like this: (article.layout, scrbook.layout, svjog.layout) \DeclareLaTeXClass{article} \DeclareLaTeXClass[scrbook]{book (koma-script)} \DeclareLaTeXClass[svjour,svjog.clo]{article (Springer - svj...
print "Layout file without \DeclearXXClass line. "
print "Layout file without \DeclareXXClass line. "
def processLayoutFile(file, bool_docbook, bool_linuxdoc): ''' process layout file and get a line of result Declear line are like this: (article.layout, scrbook.layout, svjog.layout) \DeclareLaTeXClass{article} \DeclareLaTeXClass[scrbook]{book (koma-script)} \DeclareLaTeXClass[svjour,svjog.clo]{article (Springer - svj...
if lines[i] == '\\newline ':
if string.find(lines[i],'\\newline') != -1:
def update_tabular(lines): i=0 while 1: i = find_re(lines, lyxtable_re, i) if i == -1: break prop_dict = {"family" : "default", "series" : "default", "shape" : "default", "size" : "default", "emph" : "default", "bar" : "default", "noun" : "default", "latex" : "default", "color" : "default"} # remove \LyXTable lines[i]...
\Format latex tex "TeX (latex)" L "" "%%"
\Format latex tex "TeX (latex)" l "" "%%"
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
dtl_tools = 'true'
dtl_tools = True
def checkDTLtools(): ''' Check whether DTL tools are available (Windows only) ''' # Find programs! Returned path is not used now if ((os.name == 'nt' or sys.platform == 'cygwin') and checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']): dtl_tools = 'true...
dtl_tools = 'false'
dtl_tools = False
def checkDTLtools(): ''' Check whether DTL tools are available (Windows only) ''' # Find programs! Returned path is not used now if ((os.name == 'nt' or sys.platform == 'cygwin') and checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']): dtl_tools = 'true...
if (dtl_tools == 'true'):
if dtl_tools:
def checkLatex(dtl_tools): ''' Check latex, return lyx_check_config ''' if (dtl_tools == 'true'): # Windows only: DraftDVI converter_entry = r'''\converter latex dvi2 "%%" "latex"
if (dtl_tools == 'true'):
if dtl_tools:
def checkFormatEntries(dtl_tools): ''' Check all formats (\Format entries) ''' checkViewer('a Tgif viewer and editor', ['tgif'], rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" "vector"']) # checkViewer('a FIG viewer and editor', ['xfig'], rc_entry = [r'\Format fig fig FIG ...
path, lilypond = checkProg('a LilyPond -> ESP/PDF/PNG converter', ['lilypond'])
path, lilypond = checkProg('a LilyPond -> EPS/PDF/PNG converter', ['lilypond'])
def checkConverterEntries(): ''' Check all converters (\converter entries) ''' checkProg('the pdflatex program', ['pdflatex $$i'], rc_entry = [ r'\converter pdflatex pdf2 "%%" "latex"' ]) ''' If we're running LyX in-place then tex2lyx will be found in ../src/tex2lyx. Add this directory to the PATH temporarily ...
if find_token(file.preamble, text[0]) != -1:
if find_token(file.preamble, text[0], 0) != -1:
def add_to_preamble(file, text): if find_token(file.preamble, text[0]) != -1: return file.preamble.extend(text)
lines[i] = lines[i] + '}{'
if params['use_parbox'] == '1': lines[i] = lines[i] + '}{' else: lines[i] = lines[i] + '}'
def convert_frameless_box(lines): pos = ['t', 'c', 'b'] inner_pos = ['c', 't', 'b', 's'] i = 0 while 1: i = find_token(lines, '\\begin_inset Frameless', i) if i == -1: return j = find_end_of_inset(lines, i) if j == -1: sys.stderr.write("Malformed lyx file: Missing '\\end_inset'\n") i = i + 1 continue del lines[i] # Ga...
if len(txt) > 0: new = new + ["\layout Standard", "", txt]
def change_infoinset(lines): i = 0 while 1: i = find_token(lines, "\\begin_inset Info", i) if i == -1: break txt = string.lstrip(lines[i][18:]) new = ["\\begin_inset Note", "collapsed true", ""] if len(txt) > 0: new = new + ["\layout Standard", "", txt] j = find_token(lines, "\\end_inset", i) if j == -1: break for k in...
for k in range(i+1, j):
note_lines = lines[i+1:j] if len(txt) > 0: note_lines = [txt]+note_lines for line in note_lines:
def change_infoinset(lines): i = 0 while 1: i = find_token(lines, "\\begin_inset Info", i) if i == -1: break txt = string.lstrip(lines[i][18:]) new = ["\\begin_inset Note", "collapsed true", ""] if len(txt) > 0: new = new + ["\layout Standard", "", txt] j = find_token(lines, "\\end_inset", i) if j == -1: break for k in...
tmp = string.split(lines[k], '\\')
tmp = string.split(line, '\\')
def change_infoinset(lines): i = 0 while 1: i = find_token(lines, "\\begin_inset Info", i) if i == -1: break txt = string.lstrip(lines[i][18:]) new = ["\\begin_inset Note", "collapsed true", ""] if len(txt) > 0: new = new + ["\layout Standard", "", txt] j = find_token(lines, "\\end_inset", i) if j == -1: break for k in...
file.header[j+1:j+1] = conv[paperpackage]
file.header[j+1:j+1] = [conv[paperpackage]]
def remove_paperpackage(file): i = find_token(file.header, '\\paperpackage', 0) if i == -1: return paperpackage = split(file.header[i])[1] if paperpackage in ("a4", "a4wide", "widemarginsa4"): j = find_token(file.header, '\\begin_preamble', 0) conv = {"a4":"\\usepackage{a4}","a4wide": "\\usepackage{a4wide}", "widema...
ignore erroes when file does not exist, or is a directory.
ignore errors when file does not exist, or is a directory.
def removeFiles(filenames): '''utility function: 'rm -f' ignore erroes when file does not exist, or is a directory. ''' for file in filenames: try: os.remove(file) except: pass
def checkCygwinPath():
def checkCygwinPath(srcdir):
def checkCygwinPath(): ''' Adjust PATH for Win32 (Cygwin) ''' if sys.platform == 'cygwin': from tempfile import mkstemp fd, tmpfname = mkstemp(suffix='.ltx') os.write(fd, r'''
inpname = cmdOutput('cygpath -w ' + tmpfname).replace('\\', '/')
inpname = cmdOutput('cygpath -m ' + tmpfname)
def checkCygwinPath(): ''' Adjust PATH for Win32 (Cygwin) ''' if sys.platform == 'cygwin': from tempfile import mkstemp fd, tmpfname = mkstemp(suffix='.ltx') os.write(fd, r'''
srcdir = cmdOutput('cygpath -w ' + srcdir).replace(r'\\', '')
srcdir = cmdOutput('cygpath -m ' + srcdir)
def checkCygwinPath(): ''' Adjust PATH for Win32 (Cygwin) ''' if sys.platform == 'cygwin': from tempfile import mkstemp fd, tmpfname = mkstemp(suffix='.ltx') os.write(fd, r'''
else: print "configure: cygwin detected; path correction is not needed" removeFiles( [ tmpfname, wtmpfname ])
tmpbname,ext = os.path.splitext(os.path.basename(tmpfname)) wtmpbname,ext = os.path.splitext(os.path.basename(wtmpfname)) removeFiles( [ tmpfname, wtmpfname, tmpbname + '.log', \ tmpbname + '.aux', wtmpbname + '.log', wtmpbname + '.aux' ] )
def checkCygwinPath(): ''' Adjust PATH for Win32 (Cygwin) ''' if sys.platform == 'cygwin': from tempfile import mkstemp fd, tmpfname = mkstemp(suffix='.ltx') os.write(fd, r'''
def checkLatexConfig(check_config):
def processLayoutFile(file, bool_docbook, bool_linuxdoc): ''' process layout file and get a line of result Declear line are like this: (article.layout, scrbook.layout, svjog.layout) \DeclareLaTeXClass{article} \DeclareLaTeXClass[scrbook]{book (koma-script)} \DeclareLaTeXClass[svjour,svjog.clo]{article (Springer - svj...
def checkLatexConfig(check_config): ''' Explore the LaTeX configuration ''' print 'checking LaTeX configuration... ', # First, remove the files that we want to re-create removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed']) # if not check_config: print ' default values' print '+checking list of textclasses......
p1 = re.compile(r'\Declare(LaTeX|DocBook|LinuxDoc)Class') p2 = re.compile(r'^.*\DeclareLaTeXClass *(.*)') p3 = re.compile(r'^.*\DeclareDocBookClass *(.*)') p4 = re.compile(r'^.*\DeclareLinuxDocClass *(.*)') p5 = re.compile(r'\[([^,]*),[^]]*\]') p6 = re.compile('^{') p7 = re.compile(r'\[([^]]*)\] *{([^}]*)}')
def checkLatexConfig(check_config): ''' Explore the LaTeX configuration ''' print 'checking LaTeX configuration... ', # First, remove the files that we want to re-create removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed']) # if not check_config: print ' default values' print '+checking list of textclasses......
for line in open(file).readlines(): if p1.search(line) == None: continue line = p2.sub(r'\1 "false"', line) line = p3.sub(r'\1 "' + bool_docbook + '"', line) line = p4.sub(r'\1 "' + bool_linuxdoc + '"', line) line = p5.sub(r'[\1]', line) line = p6.sub("[" + classname + "]{", line) line = p7.sub( "'" + classname + "'" +...
tx.write(processLayoutFile(file, bool_docbook, bool_linuxdoc))
def checkLatexConfig(check_config): ''' Explore the LaTeX configuration ''' print 'checking LaTeX configuration... ', # First, remove the files that we want to re-create removeFiles(['textclass.lst', 'packages.lst', 'chkconfig.sed']) # if not check_config: print ' default values' print '+checking list of textclasses......
writeToFile('chkconfig.sed', '
writeToFile('chkconfig.sed', 's!@.*@!???!g\n')
def createLaTeXConfig(): ''' create LaTeXConfig.lyx ''' # if chkconfig.sed does not exist (because LaTeX did not run), # then provide a standard version. if not os.path.isfile('chkconfig.sed'): writeToFile('chkconfig.sed', '##s/@.*@/???/g\n') print "creating packages.lst" # if packages.lst does not exist (because LaTeX...
for line in range(len(lyxin)): lyxin[line] = lyxin[line].replace(fr, to)
if fr == '@.*@': for line in range(len(lyxin)): lyxin[line] = re.sub('@.*@', to, lyxin[line]) else: for line in range(len(lyxin)): lyxin[line] = lyxin[line].replace(fr, to)
def createLaTeXConfig(): ''' create LaTeXConfig.lyx ''' # if chkconfig.sed does not exist (because LaTeX did not run), # then provide a standard version. if not os.path.isfile('chkconfig.sed'): writeToFile('chkconfig.sed', '##s/@.*@/???/g\n') print "creating packages.lst" # if packages.lst does not exist (because LaTeX...
checkCygwinPath()
checkCygwinPath(srcdir)
def removeExtraFiles(): # Remove superfluous files if we are not writing in the main lib # directory for file in [outfile, 'textclass.lst', 'packages.lst', \ 'doc/LaTeXConfig.lyx']: try: # we rename the file first, so that we avoid comparing a file with itself os.rename(file, file + '.new') syscfg = open( os.path.join(...
checkLatexConfig( lyx_check_config and LATEX != '')
checkLatexConfig( lyx_check_config and LATEX != '', bool_docbook, bool_linuxdoc)
def removeExtraFiles(): # Remove superfluous files if we are not writing in the main lib # directory for file in [outfile, 'textclass.lst', 'packages.lst', \ 'doc/LaTeXConfig.lyx']: try: # we rename the file first, so that we avoid comparing a file with itself os.rename(file, file + '.new') syscfg = open( os.path.join(...
convert = [[222, [insert_tracking_changes, add_end_header]],
convert = [[222, [insert_tracking_changes, add_end_header, convert_amsmath]],
def remove_quotestimes(file): i = find_token(file.header, '\\quotes_times', 0) if i == -1: return del file.header[i]
[221, [rm_end_header, rm_tracking_changes, rm_body_changes]]]
[221, [revert_amsmath, rm_end_header, rm_tracking_changes, rm_body_changes]]]
def remove_quotestimes(file): i = find_token(file.header, '\\quotes_times', 0) if i == -1: return del file.header[i]
def checkBoostLibraries(conf, lib, pathes): ''' look for boost libraries ''' conf.Message('Checking for boost library %s... ' % lib) for path in pathes:
def checkBoostLibraries(conf, libs, lib_paths, inc_paths, isDebug): ''' look for boost libraries libs: library names lib_paths: try these paths for boost libraries inc_paths: try these paths for boost headers isDebug: if true, use debug libraries ''' conf.Message('Checking for boost library %s... ' % ', '.join(libs))...
def checkBoostLibraries(conf, lib, pathes): ''' look for boost libraries ''' conf.Message('Checking for boost library %s... ' % lib) for path in pathes: # direct form: e.g. libboost_iostreams.a if os.path.isfile(os.path.join(path, 'lib%s.a' % lib)): conf.Result('yes') return (path, lib) # check things like libboost_ios...
if os.path.isfile(os.path.join(path, 'lib%s.a' % lib)):
if False not in [os.path.isfile(os.path.join(path, 'libboost_%s.a' % lib)) for lib in libs]:
def checkBoostLibraries(conf, lib, pathes): ''' look for boost libraries ''' conf.Message('Checking for boost library %s... ' % lib) for path in pathes: # direct form: e.g. libboost_iostreams.a if os.path.isfile(os.path.join(path, 'lib%s.a' % lib)): conf.Result('yes') return (path, lib) # check things like libboost_ios...
return (path, lib) files = glob.glob(os.path.join(path, 'lib%s-*.a' % lib)) if len(files) >= 1: conf.Result('yes') return (path, files[0].split(os.sep)[-1][3:-2]) conf.Result('n') return ('','')
found_lib = True lib_path = path lib_names = libs break for lib in libs: files = glob.glob(os.path.join(path, 'libboost_%s-*.a' % lib)) if len(files) > 0: if isDebug: files = filter(lambda x: re.search('libboost_%s-\w+-mt-d-[\d-]+' % lib, x), files) else: files = filter(lambda x: re.search('libboost_%s-\w+-mt-[\d-]+'...
def checkBoostLibraries(conf, lib, pathes): ''' look for boost libraries ''' conf.Message('Checking for boost library %s... ' % lib) for path in pathes: # direct form: e.g. libboost_iostreams.a if os.path.isfile(os.path.join(path, 'lib%s.a' % lib)): conf.Result('yes') return (path, lib) # check things like libboost_ios...
if ascent >= 0 and descent >= 0:
if ascent >= 0 or descent >= 0:
def extract_metrics_info(dvipng_stdout, metrics_file): metrics = open(metrics_file, 'w')
if frac < 0 or frac > 1:
if frac < 0:
def extract_metrics_info(dvipng_stdout, metrics_file): metrics = open(metrics_file, 'w')
print 'Use library ' % lib_files[0]
print 'Use library %s' % lib_files[0]
def checkBoostLibraries(conf, libs, lib_paths, inc_paths, version, isDebug): ''' look for boost libraries libs: library names lib_paths: try these paths for boost libraries inc_paths: try these paths for boost headers version: required boost version isDebug: if true, use debug libraries ''' conf.Message('Checking f...
j = find_token_backwards(lines,"\\layout", i-1)
j = get_paragraph(lines, i)
def combine_ert(lines): i = 0 while 1: i = find_token(lines, "\\begin_inset ERT", i) if i == -1: break j = find_token_backwards(lines,"\\layout", i-1) count = 0 text = [] while is_ert_paragraph(lines, j): count = count+1 i2 = find_token(lines, "\\layout", j+1) k = find_token(lines, "\\end_inset", i2+1) text = text+lin...
if major >= 2 and minor >= 3: return tempfile.mkstemp() tmp_name = tempfile.mktemp() return open(tmp_name, 'w'), tmp_name
if major >= 2 and minor >= 0: return tempfile.TemporaryFile() else: return TempFile()
def mkstemp(): major, minor = get_version_info() if major >= 2 and minor >= 3: return tempfile.mkstemp() tmp_name = tempfile.mktemp() return open(tmp_name, 'w'), tmp_name
tmp, tmp_name = mkstemp()
tmp = mkstemp()
def legacy_latex_file(latex_file, fg_color, bg_color): use_preview_re = re.compile("(\\\\usepackage\[[^]]+)(\]{preview})") tmp, tmp_name = mkstemp() success = 0 for line in open(latex_file, 'r').readlines(): match = use_preview_re.match(line) if match == None: tmp.write(line) continue success = 1 tmp.write("%s,dvips...
tmp.close() shutil.copy(tmp_name, latex_file) os.remove(tmp_name)
copyfileobj(tmp, open(latex_file,"wb"), 1)
"clippath fill setrgbcolor}bind def end}}}\n" \
t.append("%s -left $IN" % pnmcrop, 'f-') t.append("%s -right > $OUT" % pnmcrop, '-f') tmp, tmp_name = mkstemp() tmp.close() os.remove(tmp_name)
t.append("%s -left" % pnmcrop, '--') t.append("%s -right" % pnmcrop, '--')
def crop_files(pnmcrop, basename): t = pipes.Template() t.append("%s -left $IN" % pnmcrop, 'f-') t.append("%s -right > $OUT" % pnmcrop, '-f') tmp, tmp_name = mkstemp() tmp.close() os.remove(tmp_name) for file in glob.glob("%s*.ppm" % basename): if t.copy(file, tmp_name): shutil.copy(tmp_name, file) os.remove(tmp_name...
if t.copy(file, tmp_name): shutil.copy(tmp_name, file) os.remove(tmp_name)
tmp = mkstemp() new = t.open(file, "r") copyfileobj(new, tmp) if not new.close(): copyfileobj(tmp, open(file,"wb"))
def crop_files(pnmcrop, basename): t = pipes.Template() t.append("%s -left $IN" % pnmcrop, 'f-') t.append("%s -right > $OUT" % pnmcrop, '-f') tmp, tmp_name = mkstemp() tmp.close() os.remove(tmp_name) for file in glob.glob("%s*.ppm" % basename): if t.copy(file, tmp_name): shutil.copy(tmp_name, file) os.remove(tmp_name...
while not string.strip(self.body[k]) and string.split(self.body[k])[0] in allowed_parameters:
while not string.strip(self.body[k]) or string.split(self.body[k])[0] in allowed_parameters:
def get_toc(self, depth = 4): " Returns the TOC of this LyX document." paragraphs_filter = {'Title' : 0,'Chapter' : 1, 'Section' : 2, 'Subsection' : 3, 'Subsubsection': 4} allowed_insets = ['Quotes'] allowed_parameters = '\\paragraph_spacing', '\\noindent', '\\align', '\\labelwidthstring', "\\start_of_appendix", "\\lef...
"\\paperpackage none",
def set_header(self, **params): # set default values self.header.extend([ "#LyX xxxx created this file. For more info see http://www.lyx.org/", "\\lyxformat xxx", "\\begin_document", "\\begin_header", "\\textclass article", "\\language english", "\\inputencoding auto", "\\fontscheme default", "\\graphics default", "\\p...
import SCons from SCons.Script.SConscript import SConsEnvironment SConsEnvironment.Chmod = SCons.Action.ActionFactory(os.chmod, lambda dest, mode: 'Chmod("%s", 0%o)' % (dest, mode)) def installPerm(target, source, env, perm): ''' install program with permission, will copy files recursively if needed ''' target_dir =...
def setLoggedSpawn(env, logfile = '', longarg=False, info=''): ''' This function modify env and allow logging of commands to a logfile. If the argument is too long a win32 spawn will be used instead of the system one ''' # # create a new spwn object ls = loggedSpawn(env, logfile, longarg, info) # replace the old SPAWN ...
extern "C" size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); size_t iconv(); int main() { return 1;
// this declaration will fail when there already exists a non const char** // version which returns size_t double iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); int main() { return 0;
def checkIconvConst(conf): ''' check the declaration of iconv ''' check_iconv_const = '''
return full_path
return os.path.basename(full_path)
def find_exe(candidates, path): for prog in candidates: for directory in path: if os.name == "nt": full_path = os.path.join(directory, prog + ".exe") else: full_path = os.path.join(directory, prog) if os.access(full_path, os.X_OK): return full_path return None
new.append("\trotateOrigin center")
new.append("\trotateOrigin leftBaseline")
def remove_figinset(lines): i = 0 while 1: i = find_token(lines, "\\begin_inset Figure", i) if i == -1: break j = find_end_of_inset(lines, i) lyxwidth = string.split(lines[i])[3]+"pt" lyxheight = string.split(lines[i])[4]+"pt" filename = get_value(lines, "file", i+1, j) width = get_length(lines, "width", i+1, j) # w...
paperpackage = "default" file.header[i] = replace(file.header[i], paperpackage, packages[paperpackage])
file.header[i] = file.header[i] + ' widemarginsa4'
def convert_paperpackage(file): i = find_token(file.header, "\\paperpackage", 0) if i == -1: return packages = {'default':'none','a4':'none', 'a4wide':'a4', 'widemarginsa4':'a4wide'} if len(split(file.header[i])) > 1: paperpackage = split(file.header[i])[1] else: paperpackage = "default" file.header[i] = replace(file....
if height == ' "0pt"':
if height == ' "0pt"' or height == ' "0"':
def convert_minipage(file): """ Convert minipages to the box inset. We try to use the same order of arguments as lyx does. """ pos = ["t","c","b"] inner_pos = ["c","t","b","s"] i = 0 while 1: i = find_token(file.body, "\\begin_inset Minipage", i) if i == -1: return file.body[i] = "\\begin_inset Box Frameless" i = i +...
inner_pos[params['inner_pos']] != pos[params['position']] or
def convert_frameless_box(file): pos = ['t', 'c', 'b'] inner_pos = ['c', 't', 'b', 's'] i = 0 while 1: i = find_token(file.body, '\\begin_inset Frameless', i) if i == -1: return j = find_end_of_inset(file.body, i) if j == -1: file.warning("Malformed LyX file: Missing '\\end_inset'.") i = i + 1 continue del file.body[i]...
lines = lines[:i] + new_table + lines[j:]
lines[i:j] = new_table
def update_tabular(lines): i=0 while 1: i = find_token(lines, '\\begin_inset Tabular', i) if i == -1: break i = i +1 # scan table header meta-info lines[i] = string.replace(lines[i], 'LyXTabular version="1"', 'lyxtabular version="2"') j = find_token(lines, '</LyXTabular>', i) + 1 if j == 0: sys.stderr.write( "Error...
fd, tmpfname = mkstemp(suffix='.ltx')
fd, tmpfname = mkstemp(suffix='.ltx', dir='/tmp')
def checkCygwinPath(srcdir): ''' Adjust PATH for Win32 (Cygwin) ''' if sys.platform == 'cygwin': from tempfile import mkstemp fd, tmpfname = mkstemp(suffix='.ltx') os.write(fd, r'''
wfd, wtmpfname = mkstemp(suffix='.ltx')
wfd, wtmpfname = mkstemp(suffix='.ltx', dir='/tmp')
def checkCygwinPath(srcdir): ''' Adjust PATH for Win32 (Cygwin) ''' if sys.platform == 'cygwin': from tempfile import mkstemp fd, tmpfname = mkstemp(suffix='.ltx') os.write(fd, r'''
type = lines[i][33:-3]
type = re.search(r"listof(\w*)", lines[i]).group(1)[:-1]
def change_listof(lines): i = 0 while 1: i = find_token(lines, "\\begin_inset LatexCommand \\listof", i) if i == -1: break type = lines[i][33:-3] lines[i] = "\\begin_inset FloatList "+type i = i+1
conf.Result('two')
ret = conf.TryLink(check_mkdir_one_arg_source2, '.c') if ret: conf.Result('one') else: conf.Result('two')
def checkMkdirOneArg(conf): check_mkdir_one_arg_source = """
rc_entry = [ r'\converter latex pdf2 "%%" "latex"' ])
rc_entry = [ r'\converter pdflatex pdf2 "%%" "latex"' ])
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
\Format latex tex LaTeX L "" "%%"
\Format latex tex "TeX (latex)" L "" "%%"
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
writeToFile('a b.tex', r'\nonstopmode\message{working^^J}' ) if ''.join(cmdOutput(LATEX + ' "a b"')).find('working') != -1:
writeToFile('a b.tex', r'\message{working^^J}' ) if os.name == 'nt': latex_out = cmdOutput(LATEX + r""" "\nonstopmode\input{\"a b\"}" """) else: latex_out = cmdOutput(LATEX + r""" '\nonstopmode\input{"a b"}' """) if 'working' in latex_out:
def checkTeXAllowSpaces(): ''' Let's check whether spaces are allowed in TeX file names ''' tex_allows_spaces = 'false' if lyx_check_config: print "Checking whether TeX allows spaces in file names... ", writeToFile('a b.tex', r'\nonstopmode\message{working^^J}' ) if ''.join(cmdOutput(LATEX + ' "a b"')).find('working') ...
while not self.body[k] or self.body[k][0] == '\\':
while not string.strip(self.body[k]) and string.split(self.body[k])[0] in allowed_parameters:
def get_toc(self, depth = 4): " Returns the TOC of this LyX document." paragraphs_filter = {'Title' : 0,'Chapter' : 1, 'Section' : 2, 'Subsection' : 3, 'Subsubsection': 4} allowed_insets = ['Quotes']
def checkProg(description, progs, rc_entry = [], path = [] ):
def checkProg(description, progs, rc_entry = [], path = [], not_found = ''):
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
or 'none' is no program is found. 3. several patterns for each prog and 'none'. This is used
or '' if no program is found. 3. several patterns for each prog and not_found. This is used
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
want 'none' entry to be added to the RC file, you can specify an entry for each prog and use '' for the 'none' entry.
want not_found entry to be added to the RC file, you can specify an entry for each prog and use '' for the not_found entry. not_found: the value that should be used instead of '' if no program was found
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
print "rc entry should have one item or item for each prog and none."
print "rc entry should have one item or item for each prog and not_found."
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
addToRC(rc_entry[-1].replace('%%', 'none')) return ['', 'none']
addToRC(rc_entry[-1].replace('%%', not_found)) return ['', not_found] def checkViewer(description, progs, rc_entry = [], path = []): ''' The same as checkProg, but for viewers and editors ''' return checkProg(description, progs, rc_entry, path, not_found = 'auto')
def checkProg(description, progs, rc_entry = [], path = [] ): ''' This function will search a program in $PATH plus given path If found, return directory and program name (not the options). description: description of the program progs: check programs, for each prog, the first word is used for searching but the whole...
if os.name == 'nt' or sys.platform == 'cygwin':
if ((os.name == 'nt' or sys.platform == 'cygwin') and checkProg('DVI to DTL converter', ['dv2dt']) != ['', ''] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', '']):
def checkLatex(): ''' Check latex, return lyx_check_config ''' # Find programs! Returned path is not used now if os.name == 'nt' or sys.platform == 'cygwin': # Windows only: DraftDVI if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: convert...
if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: converter_entry = r'''\converter latex dvi2 "%%" "latex"
converter_entry = r'''\converter latex dvi2 "%%" "latex"
def checkLatex(): ''' Check latex, return lyx_check_config ''' # Find programs! Returned path is not used now if os.name == 'nt' or sys.platform == 'cygwin': # Windows only: DraftDVI if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: convert...
else: converter_entry = r'\converter latex dvi "%%" "latex"'
def checkLatex(): ''' Check latex, return lyx_check_config ''' # Find programs! Returned path is not used now if os.name == 'nt' or sys.platform == 'cygwin': # Windows only: DraftDVI if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: convert...
if LATEX != 'none':
if LATEX != '':
def checkLatex(): ''' Check latex, return lyx_check_config ''' # Find programs! Returned path is not used now if os.name == 'nt' or sys.platform == 'cygwin': # Windows only: DraftDVI if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: convert...
checkProg('a Tgif viewer and editor', ['tgif'], rc_entry = [ r'\Format tgif obj Tgif "" "%%" "%%" ""']) checkProg('a FIG viewer and editor', ['xfig'], rc_entry = [ r'\Format fig fig FIG "" "%%" "%%" ""'] ) checkProg('a Grace viewer and editor', ['xmgrace'], rc...
checkViewer('a Tif viewer and editor', ['tgif'], rc_entry = [r'\Format tgif obj Tgif "" "%%" "%%" ""']) checkViewer('a FIG viewer and editor', ['xfig'], rc_entry = [r'\Format fig fig FIG "" "%%" "%%" ""']) checkViewer('a Grace viewer and editor', ['xmgrace'], ...
def checkFormatEntries(): ''' Check all formats (\Format entries) ''' checkProg('a Tgif viewer and editor', ['tgif'], rc_entry = [ r'\Format tgif obj Tgif "" "%%" "%%" ""']) # checkProg('a FIG viewer and editor', ['xfig'], rc_entry = [ r'\Format fig fig FIG "" "...
checkProg('a text editor', ['xemacs', 'gvim', 'kedit', 'kwrite', 'kate', \
checkViewer('a text editor', ['xemacs', 'gvim', 'kedit', 'kwrite', 'kate', \
def checkFormatEntries(): ''' Check all formats (\Format entries) ''' checkProg('a Tgif viewer and editor', ['tgif'], rc_entry = [ r'\Format tgif obj Tgif "" "%%" "%%" ""']) # checkProg('a FIG viewer and editor', ['xfig'], rc_entry = [ r'\Format fig fig FIG "" "...
checkProg('a Postscript previewer', ['gv', 'ghostview -swap', 'kghostview'], rc_entry = [ r'''\Format eps eps EPS "" "%%" "" "" \Format ps ps Postscript t "%%" "" "document"''' ]) checkProg('a PDF previewer', ['acrobat', 'acroread', 'gv', 'ghostview', \
checkViewer('a Postscript previewer', ['gv', 'ghostview -swap', 'kghostview'], rc_entry = [r'''\Format eps eps EPS "" "%%" "" "" \Format ps ps Postscript t "%%" "" "document"''']) checkViewer('a PDF previewer', ['acrobat', 'acroread', 'gv', 'ghostview', \
def checkFormatEntries(): ''' Check all formats (\Format entries) ''' checkProg('a Tgif viewer and editor', ['tgif'], rc_entry = [ r'\Format tgif obj Tgif "" "%%" "%%" ""']) # checkProg('a FIG viewer and editor', ['xfig'], rc_entry = [ r'\Format fig fig FIG "" "...
\Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document"''' ]) checkProg('a DVI previewer', ['xdvi', 'kdvi'], rc_entry = [ r'\Format dvi dvi DVI D "%%" "" "document"' ]) if os.name == 'nt' or sys.platform == 'cygwin':
\Format pdf3 pdf "PDF (dvipdfm)" m "%%" "" "document"''']) checkViewer('a DVI previewer', ['xdvi', 'kdvi'], rc_entry = [r'\Format dvi dvi DVI D "%%" "" "document"']) if ((os.name == 'nt' or sys.platform == 'cygwin') and checkProg('DVI to DTL converter', ['dv2dt']) != ['...
def checkFormatEntries(): ''' Check all formats (\Format entries) ''' checkProg('a Tgif viewer and editor', ['tgif'], rc_entry = [ r'\Format tgif obj Tgif "" "%%" "%%" ""']) # checkProg('a FIG viewer and editor', ['xfig'], rc_entry = [ r'\Format fig fig FIG "" "...
if checkProg('DVI to DTL converter', ['dv2dt']) != ['', 'none'] and checkProg('DTL to DVI converter', ['dt2dv']) != ['', 'none']: addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document"') checkProg('a HTML previewer', ['mozilla file://$$p$$i', 'netscape'], rc_entry = [ r'\Format html html ...
addToRC(r'\Format dvi2 dvi DraftDVI "" "" "document"') checkViewer('a HTML previewer', ['mozilla file://$$p$$i', 'netscape'], rc_entry = [r'\Format html html HTML H "%%" "" "document"'])
def checkFormatEntries(): ''' Check all formats (\Format entries) ''' checkProg('a Tgif viewer and editor', ['tgif'], rc_entry = [ r'\Format tgif obj Tgif "" "%%" "%%" ""']) # checkProg('a FIG viewer and editor', ['xfig'], rc_entry = [ r'\Format fig fig FIG "" "...
r ]) if LINUXDOC != 'none':
r ]) if LINUXDOC != '':
def checkLinuxDoc(): ''' Check linuxdoc ''' # path, LINUXDOC = checkProg('SGML-tools 1.x (LinuxDoc)', ['sgml2lyx'], rc_entry = [ r'''\converter linuxdoc lyx "sgml2lyx $$i" ""
r]) if DOCBOOK != 'none':
r]) if DOCBOOK != '':
def checkDocBook(): ''' Check docbook ''' path, DOCBOOK = checkProg('SGML-tools 2.x (DocBook) or db2x scripts', ['sgmltools', 'db2dvi'], rc_entry = [ r'''\converter docbook dvi "sgmltools -b dvi $$i" ""
r'\ascii_roff_command "none"' ])
r'\ascii_roff_command ""' ])
def checkOtherEntries(): ''' entries other than Format and Converter ''' checkProg('a *roff formatter', ['groff', 'nroff'], rc_entry = [ r'\ascii_roff_command "groff -t -Tlatin1 $$FName"', r'\ascii_roff_command "tbl $$FName | nroff"', r'\ascii_roff_command "none"' ]) checkProg('ChkTeX', ['chktex -n1 -n3 -n6 -n9 -n22 -n...
if opt.input == stdin: dir = "" else: dir = os.path.dirname(os.path.abspath(opt.input.name))
def convert_graphics(lines, opt): """ Add extension to filenames of insetgraphics if necessary. """ if opt.input == stdin: dir = "" else: dir = os.path.dirname(os.path.abspath(opt.input.name)) i = 0 while 1: i = find_token(lines, "\\begin_inset Graphics", i) if i == -1: return j = find_token2(lines, "filename", i) if ...
absname = os.path.normpath(os.path.join(dir, filename))
absname = os.path.normpath(os.path.join(opt.dir, filename))
def convert_graphics(lines, opt): """ Add extension to filenames of insetgraphics if necessary. """ if opt.input == stdin: dir = "" else: dir = os.path.dirname(os.path.abspath(opt.input.name)) i = 0 while 1: i = find_token(lines, "\\begin_inset Graphics", i) if i == -1: return j = find_token2(lines, "filename", i) if ...
file.warning("Malformed LyX file: Missing '\\begin_preamble'.") return
file.header.extend(['\\begin_preamble'] + text + ['\\end_preamble']) return
def add_to_preamble(file, text): i = find_token(file.header, '\\begin_preamble', 0) if i == -1: file.warning("Malformed LyX file: Missing '\\begin_preamble'.") return j = find_token(file.header, '\\end_preamble', i) if j == -1: file.warning("Malformed LyX file: Missing '\\end_preamble'.") return if find_token(file.head...
return
file.warning("Adding it now and hoping for the best.") file.header.append('\\end_preamble') j = len(file.header)
def add_to_preamble(file, text): i = find_token(file.header, '\\begin_preamble', 0) if i == -1: file.warning("Malformed LyX file: Missing '\\begin_preamble'.") return j = find_token(file.header, '\\end_preamble', i) if j == -1: file.warning("Malformed LyX file: Missing '\\end_preamble'.") return if find_token(file.head...
params = {'position':'0', 'hor_pos':'c', 'has_inner_box':'1', 'inner_pos':'1', 'use_parbox':'0', 'width':'100col%',
params = {'position':0, 'hor_pos':'c', 'has_inner_box':'1', 'inner_pos':1, 'use_parbox':'0', 'width':'100col%',
def convert_frameless_box(file): pos = ['t', 'c', 'b'] inner_pos = ['c', 't', 'b', 's'] i = 0 while 1: i = find_token(file.body, '\\begin_inset Frameless', i) if i == -1: return j = find_end_of_inset(file.body, i) if j == -1: file.warning("Malformed LyX file: Missing '\\end_inset'.") i = i + 1 continue del file.body[i]...
'widemarginsa4':''} paperpackage = split(file.header[i])[1]
'widemarginsa4':'', 'default': 'default'} if len(split(file.header[i])) > 1: paperpackage = split(file.header[i])[1] else: paperpackage = 'default'
def revert_paperpackage(file): i = find_token(file.header, "\\paperpackage", 0) if i == -1: file.warning("Malformed lyx file: Missing '\\paperpackage'.") return packages = {'none':'a4', 'a4':'a4wide', 'a4wide':'widemarginsa4', 'widemarginsa4':''} paperpackage = split(file.header[i])[1] file.header[i] = replace(file.he...
lines[i] = '<cell multicolumn="%s" alignment="%s" valignment="%s" topline="%s" bottomline="%s" leftline="%s" rightline="%s" rotate="%s" usebox="%s" width="%s" special="%s">' % ( val[0], align_table[val[1]], align_table[val[2]], bool_table(val[3]), bool_table(val[4]), bool_table(val[5]), bool_table(val[6]), bool_table(v...
lines[i] = '<cell multicolumn="%s" alignment="%s" valignment="%s" topline="%s" bottomline="%s" leftline="%s" rightline="%s" rotate="%s" usebox="%s" width="%s" special="%s">' % ( val[0], align_table[val[1]], align_vertical[val[2]], bool_table(val[3]), bool_table(val[4]), bool_table(val[5]), bool_table(val[6]), bool_tabl...
def table_update(lines): lines[1] = string.replace(lines[1], '<Features', '<features') res = features_re.match( lines[1] ) if res: val = res.groups() lines[1] = '<features rotate="%s" islongtable="%s" endhead="%s" endfirsthead="%s" endfoot="%s" endlastfoot="%s">' % (bool_table(val[0]), bool_table(val[1]), val[2], val[3...
% ( align_table[val[0]], align_table[val[1]], bool_table(val[2]), bool_table(val[3]), val[4],val[5])
% ( align_table[val[0]], align_vertical[val[1]], bool_table(val[2]), bool_table(val[3]), val[4],val[5])
def table_update(lines): lines[1] = string.replace(lines[1], '<Features', '<features') res = features_re.match( lines[1] ) if res: val = res.groups() lines[1] = '<features rotate="%s" islongtable="%s" endhead="%s" endfirsthead="%s" endfoot="%s" endlastfoot="%s">' % (bool_table(val[0]), bool_table(val[1]), val[2], val[3...
lines.append('%s "%s"' % (commandparams_info[name][0], option1[1:-1].replace('"', '\"')))
lines.append('%s "%s"' % (commandparams_info[name][0], option1[1:-1].replace('"', '\\"')))
def convert_commandparams(document): """ Convert \begin_inset LatexCommand \cmdname[opt1][opt2]{arg} \end_inset to \begin_inset LatexCommand cmdname name1 "opt1" name2 "opt2" name3 "arg" \end_inset name1, name2 and name3 can be different for each command.
lines.append('%s "%s"' % (commandparams_info[name][1], option2[1:-1].replace('"', '\"')))
lines.append('%s "%s"' % (commandparams_info[name][1], option2[1:-1].replace('"', '\\"')))
def convert_commandparams(document): """ Convert \begin_inset LatexCommand \cmdname[opt1][opt2]{arg} \end_inset to \begin_inset LatexCommand cmdname name1 "opt1" name2 "opt2" name3 "arg" \end_inset name1, name2 and name3 can be different for each command.
lines.append('%s "%s"' % (commandparams_info[name][2], argument[1:-1].replace('"', '\"')))
lines.append('%s "%s"' % (commandparams_info[name][2], argument[1:-1].replace('"', '\\"')))
def convert_commandparams(document): """ Convert \begin_inset LatexCommand \cmdname[opt1][opt2]{arg} \end_inset to \begin_inset LatexCommand cmdname name1 "opt1" name2 "opt2" name3 "arg" \end_inset name1, name2 and name3 can be different for each command.
env['QT4_UIC4COM'] = '$QT4_UIC -o $TARGET $SOURCE'
env['QT4_UIC4COM'] = '$QT4_UIC -tr lyx::qt_ -o $TARGET $SOURCE'
def scanResources(node, env, path, arg): contents = node.get_contents() includes = qrcinclude_re.findall(contents) return includes
lines.insert(i, 'height_special "height"')
lines.insert(i, 'height_special "totalheight"')
def convert_minipage(lines): """ Convert minipages to the box inset. We try to use the same order of arguments as lyx does. """ pos = ["t","c","b"] inner_pos = ["c","t","b","s"] i = 0 while 1: i = find_token(lines, "\\begin_inset Minipage", i) if i == -1: return lines[i] = "\\begin_inset Frameless" i = i + 1 # conve...
paperpackage = split(file.header[i])[1]
if len(split(file.header[i])) > 1: paperpackage = split(file.header[i])[1] else: paperpackage = "default"
def convert_paperpackage(file): i = find_token(file.header, "\\paperpackage", 0) if i == -1: file.warning("Malformed lyx file: Missing '\\paperpackage'.") return packages = {'default':'none','a4':'none', 'a4wide':'a4', 'widemarginsa4':'a4wide'} paperpackage = split(file.header[i])[1] file.header[i] = replace(file.head...
file.body[i] = "\\language french"
file.body[i] = "\\lang french"
def convert_french(file): regexp = re.compile(r'^\\language\s+frenchb') i = find_re(file.header, regexp, 0) if i != -1: file.header[i] = "\\language french" # Change language in the document body regexp = re.compile(r'^\\lang\s+frenchb') i = 0 while 1: i = find_re(file.body, regexp, i) if i == -1: break file.body[i] =...
lines[i:i] = ["\end_deeper","","","\\end_inset","",""]
lines[i:i] = ["\end_deeper",""]
def convert_comment(lines): i = 0 comment = "\\layout Comment" while 1: i = find_token(lines, comment, i) if i == -1: return lines[i:i+1] = ["\\layout Standard","","", "\\begin_inset Comment", "collapsed true","", "\\layout Standard"] i = i + 7 while 1: old_i = i i = find_token(lines, "\\layout", i) if i == -1: i = l...
lines.insert(i,"") lines.insert(i,"\\end_layout") i = i + 3 while struct_stack[-1] != "\\begin_deeper":
if struct_stack[-1] == '\\layout': lines.insert(i, '\\end_layout') i = i + 1
def add_end_layout(lines): i = find_token(lines, '\\layout', 0) if i == -1: return i = i + 1 struct_stack = ["\\layout"] while 1: i = find_tokens(lines, ["\\begin_inset", "\\end_inset", "\\layout", "\\begin_deeper", "\\end_deeper", "\\the_end"], i) token = split(lines[i])[0] if token == "\\begin_inset": struct_sta...
for k in env.get('SUBST_KEYS', []): if not env.has_key(k): print "Failed to subst key ", k, " from file", str(source[0]) raise
for k, v in env.items():
def env_subst(target, source, env): ''' subst variables in source by those in env, and output to target source and target are scons File() objects %key% (not key itself) is an indication of substitution ''' assert len(target) == 1 assert len(source) == 1 target_file = file(str(target[0]), "w") source_file = file(str(s...
contents = re.sub('@'+k+'@', env[k].replace('\n',r'\\n\\\n'), contents)
contents = re.sub('@'+k+'@', env.subst('$'+k).replace('\n',r'\\n\\\n'), contents) contents = re.sub('%'+k+'%', env.subst('$'+k).replace('\n',r'\\n\\\n'), contents)
def env_subst(target, source, env): ''' subst variables in source by those in env, and output to target source and target are scons File() objects %key% (not key itself) is an indication of substitution ''' assert len(target) == 1 assert len(source) == 1 target_file = file(str(target[0]), "w") source_file = file(str(s...