Jose' Matos wrote: > On Wednesday 30 July 2003 16:56, Angus Leeming wrote: >> José, I want to change the LyX file format too! In this case, changing >> from: >> >> \begin_inset LatexCommand >> \bibtex[bibtotoc,<style>]{<database1>,<database2>,<database3>} >> >> \end_inset >> >> to >> >> \begin_inset Bibtex >> filename test >> filename xampl >> style abbrvnat >> bibtotoc true >> >> \end_inset > > Just to be clear, here test and xampl are examples of <databasen>, > right? > >> Of course, I want only to output 'style' and 'bibtotoc' entries if >> they are not empty and true repectively. > > No problem. :-) > >> I also don't want to write the lyx2lyx converter myself because >> I'm a lazy bum. ;-) Could I get you to hack up a sample function >> to get me started? > > To tell you the truth this will involve to write a regular expression, > an > area that you excel as seen from your sed scripts. ;-)
Hmmm. Maybe. def convert_bibtex(lines): bibtex_header = "\\begin_inset LatexCommand \\bibtex" while 1: i = find_token(lines, bibtex_header, i) if i == -1: break # We've found a bibtex inset. # I'd like to strip bibtex_header from the front of lines[i] # In sed/sh: line=`echo $line | sed "s/$bibtex_header//"` # Does the thing have an opt arg? # I think that this regex is correct, but its not tested. optarg_rexp = re.compile(r^ *\[([^]]*)\]) optarg = optarg_rexp.search(lines[i]) optarg_contents = '' if optarg: optarg_contents = optarg.group(1) # Can we strip [<optarg_contents>] from the front of lines[i]? # lines[i] should now contain "{<list of databases>}" mainarg_rexp = re.compile(r{([^}]*)}) mainarg = mainarg_rexp.search(lines[i]) mainarg_contents = '' if mainarg: mainarg_contents = mainarg.group(1) else: # complain about a mal-formed lyx file. # optarg_contents will contain either # "bibtotoc,<style>" # or # "<style>" # mainarg_contents will contain a comma-separated list of files. I don't know enough python to proceed futher I'm afraid. Can you fill in the 'ltrim' syntax above and give me a clue about how to proceed? -- Angus