Re: python help needed
rgheck wrote: > See if r25508 works for you. It does. Thanks indeed. Jürgen
Re: python help needed
Juergen Spitzmueller wrote: rgheck wrote: I finally got around to doing this. I've also re-written the latex2lyx conversion routine so that it uses the unicodesymbols file. I'm not sure exactly what you had in mind for convert_subfig, as I don't know anything about figures, but perhaps this will let you do it now? Thanks, it's fixed. While you are at it, could you also have a look at bug 5006? See if r25508 works for you. The idea is to wrap all LaTeX commands as ERT. Working on this exposed some bugs in the previous stuff, too. I.e., we should replace \L with the corresponding unicode character, but we of course don't want to do that when it's: \LaTeX. So simple replacement mechanism didn't work, and now there is a more complicated one. rh
Re: python help needed
rgheck wrote: > I finally got around to doing this. I've also re-written the latex2lyx > conversion routine so that it uses the unicodesymbols file. > > I'm not sure exactly what you had in mind for convert_subfig, as I don't > know anything about figures, but perhaps this will let you do it now? Thanks, it's fixed. While you are at it, could you also have a look at bug 5006? Jürgen
Re: python help needed
Jürgen Spitzmüller wrote: In order to fully fix bug 4927, we need to do some LaTeX->LyX conversion, because subfigure captions can contain LaTeX constructs such as \label. Currently, subcaptions with such constructs are simply eaten (i.e., dataloss). I think we should factor out the routines of convert_latexcommand_index to a helper function which is used by convert_latexcommand_index, convert_subfig and maybe others. I failed at doing this due to limited python knowledge. I'd appreciate if someone could jump in (and maybe also clean up my really ugly convert_subfig routine). I finally got around to doing this. I've also re-written the latex2lyx conversion routine so that it uses the unicodesymbols file. I'm not sure exactly what you had in mind for convert_subfig, as I don't know anything about figures, but perhaps this will let you do it now? rh
Re: python help needed
José Matos wrote: > > I'm happy to do this, but it'll be a bit, as I "have" to go to St > > Andrews next week and will be busy. > > I am more or less on the same situation. Really busy here with several > deadlines and at the same time glad to help you after the next week. :-) Thank you both. I'll wait patiently. Jürgen
Re: python help needed
On Friday 06 June 2008 17:13:17 rgheck wrote: > I'm happy to do this, but it'll be a bit, as I "have" to go to St > Andrews next week and will be busy. I am more or less on the same situation. Really busy here with several deadlines and at the same time glad to help you after the next week. :-) > rh -- José Abílio
Re: python help needed
Juergen Spitzmueller wrote: In order to fully fix bug 4927, we need to do some LaTeX->LyX conversion, because subfigure captions can contain LaTeX constructs such as \label. Currently, subcaptions with such constructs are simply eaten (i.e., dataloss). I think we should factor out the routines of convert_latexcommand_index to a helper function which is used by convert_latexcommand_index, convert_subfig and maybe others. I failed at doing this due to limited python knowledge. I'd appreciate if someone could jump in (and maybe also clean up my really ugly convert_subfig routine). I'm happy to do this, but it'll be a bit, as I "have" to go to St Andrews next week and will be busy. rh
python help needed
In order to fully fix bug 4927, we need to do some LaTeX->LyX conversion, because subfigure captions can contain LaTeX constructs such as \label. Currently, subcaptions with such constructs are simply eaten (i.e., dataloss). I think we should factor out the routines of convert_latexcommand_index to a helper function which is used by convert_latexcommand_index, convert_subfig and maybe others. I failed at doing this due to limited python knowledge. I'd appreciate if someone could jump in (and maybe also clean up my really ugly convert_subfig routine). Thanks in advance, Jürgen
Re: Result of: Python help needed for configure.py - MiKTeX-problem
Jean-Marc Lasgouttes schrieb: Uwe> I wrote an email to the MiKTeX-developer but I don't have hope Uwe> that this could easily be fixed :-(. This is pretty bad indeed. Does latex return an error code in this case? No, nothing. He could confirm the bug, but I don't know what he plan to fix this. Uwe
Re: Result of: Python help needed for configure.py - MiKTeX-problem
> "Uwe" == Uwe Stöhr <[EMAIL PROTECTED]> writes: Uwe> When MiKTeX's option "Install Missing Packages on the fly" is set Uwe> as "Yes" but no Internet connection is open when \ifFileExists is Uwe> invoked, the latex-script is closed by MiKTeX and you get in the Uwe> console: Uwe> latex: No Data Uwe> I wrote an email to the MiKTeX-developer but I don't have hope Uwe> that this could easily be fixed :-(. This is pretty bad indeed. Does latex return an error code in this case? JMarc
Re: Result of: Python help needed for configure.py - MiKTeX-problem
> "Bo" == Bo Peng <[EMAIL PROTECTED]> writes: >> When the check is unsuccessful the line becomes invalid and >> therefore the while loop breaks. The problem of this is line 77 in >> chkconfig.ltx (command definition of \TestItem) : Bo> I did not like chkconfig.ltx but was not able to replace it. Bo> chkconfig.ltx uses latex to check latex packages and generate a Bo> result file. It would be slower and cleaner to test each package Bo> one by one in python, but I was not able to decipher the latex Bo> code. The part of chkconfig.ltx that tests for available packages could indeed use kpsewhich for testing, but I am not sure this would fix the bug above. JMarc
Re: python help needed
Am Mittwoch, 10. Januar 2007 23:18 schrieb José Matos: > On Wednesday 10 January 2007 9:33 pm, Georg Baum wrote: > > Ah, now I know the problem: If we add string literals to document.body we > > need to prefix them with u to get unicode string literals: u'bla'. Now I > > know where to search. > > That is enough to drive anyone (read me) crazy. :-) Me too, but I found a workaround: # Unfortunately we have a mixture of unciode strings and plain strings, # because we never use u'xxx' for string literals, but 'xxx'. # Therefore we may have to try two times to normalize the data. try: document.body[i] = unicodedata.normalize("NFKD", document.body[i]) except TypeError: document.body[i] = unicodedata.normalize("NFKD", unicode(document.body[i], 'utf-8')) That works, now I have to find the next bug :-( Georg
Re: Result of: Python help needed for configure.py - MiKTeX-problem
Bo Peng schrieb: The problem of this is line 77 in chkconfig.ltx (command definition of \TestItem) : I did not like chkconfig.ltx but was not able to replace it. chkconfig.ltx uses latex to check latex packages and generate a result file. It would be slower and cleaner to test each package one by one in python, but I was not able to decipher the latex code. chkconfig.ltx works fine and needn't to be replaced. The problem is here MiKTeX that quits the script instead of printing an error message and then continue. regards Uwe
Re: Result of: Python help needed for configure.py - MiKTeX-problem
When the check is unsuccessful the line becomes invalid and therefore the while loop breaks. The problem of this is line 77 in chkconfig.ltx (command definition of \TestItem) : I did not like chkconfig.ltx but was not able to replace it. chkconfig.ltx uses latex to check latex packages and generate a result file. It would be slower and cleaner to test each package one by one in python, but I was not able to decipher the latex code. Bo
Result of: Python help needed for configure.py - MiKTeX-problem
+checking for package geometry [geometry]... yes +checking for package jurabib [jurabib]... creating packages.lst creating doc/LaTeXConfig.lyx LyX: Fertig! lyx: Disabling LyX socket. And this is the problem: In the example above configure.py checks for the LaTeX-package jurabib and MiKTeX tries to install it as it isn't currently installed. As no internet connection is available this is of course unsuccessful. But now comes the problem: configure.py doesn't continue but jumps to the section where the list files are created - the created are buggy because the inspection of LaTeX was incomplete. I investigated a lot now: The reason for this is this routine in configure.py: # we have chklayouts.tex, then process it fout = os.popen(LATEX + ' wrap_chkconfig.ltx') while True: line = fout.readline() if not line: break; if re.match('^\+', line): print line, fout.close() When the check is unsuccessful the line becomes invalid and therefore the while loop breaks. The problem of this is line 77 in chkconfig.ltx (command definition of \TestItem) : \IfFileExists{\file} {} {\IfFileExists{\file.#4}{}{\existsfalse}} When MiKTeX's option "Install Missing Packages on the fly" is set as "Yes" but no Internet connection is open when \ifFileExists is invoked, the latex-script is closed by MiKTeX and you get in the console: == latex: No Data I wrote an email to the MiKTeX-developer but I don't have hope that this could easily be fixed :-(. regards Uwe
Python help needed for configure.py
Hi Bo and all others who know Phyton: I have a big problem here with my win builds due to the following problem of configure.py: MiKTeX's option "Instal missing packages on the fly" the nice feature that will automatically install LaTeX-packages LyX is checking in configure.py is set to "Yes". Now the user installs LyX without an open internet connection - everything went fine and he decides to start LyX the first time. Now configure.py is started by LyX inspecting the LaTeX-configuration: ... +checking for package floatflt [floatflt]... yes +checking for package framed [framed]... yes +checking for package geometry [geometry]... yes +checking for package jurabib [jurabib]... creating packages.lst creating doc/LaTeXConfig.lyx LyX: Fertig! lyx: Disabling LyX socket. And this is the problem: In the example above configure.py checks for the LaTeX-package jurabib and MiKTeX tries to install it as it isn't currently installed. As no internet connection is available this is of course unsuccessful. But now comes the problem: configure.py doesn't continue but jumps to the section where the list files are created - the created are buggy because the inspection of LaTeX was incomplete. How can this be fixed in the way that configure.py continued the inspection, also if an error occured for several packages? You would help me very much! (This would by the way solve bug 2829: http://bugzilla.lyx.org/show_bug.cgi?id=2829) thanks in advance and regards Uwe
Re: python help needed
On Wednesday 10 January 2007 9:33 pm, Georg Baum wrote: > Ah, now I know the problem: If we add string literals to document.body we > need to prefix them with u to get unicode string literals: u'bla'. Now I > know where to search. That is enough to drive anyone (read me) crazy. :-) > Georg -- José Abílio
Re: python help needed
Am Mittwoch, 10. Januar 2007 01:00 schrieb Enrico Forestieri: > No, the problem is that something is messed up. Apparently, > document.body[i] may already be in unicode format. Yes, that is done in LyX.py. > See for example: > http://www.red-mercury.com/blog/eclectic-tech/python-mystery-of-the-day/ > > I see that lyx_1_5.py messes up with conversions from/to unicode... Ah, now I know the problem: If we add string literals to document.body we need to prefix them with u to get unicode string literals: u'bla'. Now I know where to search. Georg
Re: python help needed
On Tue, Jan 09, 2007 at 11:28:04PM +0100, Enrico Forestieri wrote: > On Tue, Jan 09, 2007 at 11:23:52PM +0100, Enrico Forestieri wrote: > > On Tue, Jan 09, 2007 at 10:25:15PM +0100, Georg Baum wrote: > > > Am Dienstag, 9. Januar 2007 22:19 schrieb Enrico Forestieri: > > > > > > > No, I didn't try your patch. > > > > > > That does not help :-( Your script works for me, too. The strange thing > > > is > > > that the type of document.body[i] is neither a normal string nor a > > > unicode > > > string. At least the error messages seem to suggest that. > > > > I was compiling. Now I tried it. The TypeError is due to this statement: > > > > unicode(document.body[i], 'utf8') > > > > I noticed that the error occurs when document.body[i] is empty, but even > > after taking care of this it still occurs, so maybe it is due to some > > wrong encoding. I am using the following trick to debug, maybe it can > > be of help to you as I really don't know what I should expect: > > I bet the problem are the backslashes... No, the problem is that something is messed up. Apparently, document.body[i] may already be in unicode format. See for example: http://www.red-mercury.com/blog/eclectic-tech/python-mystery-of-the-day/ I see that lyx_1_5.py messes up with conversions from/to unicode... -- Enrico
Re: python help needed
On Tuesday 09 January 2007 6:46 pm, Georg Baum wrote: > José or any other python expert, I need your help. The attached patch is > the lyx2lyx part of the "getting rid of InsetLaTeXAccent" patch. > convert_accent works well, but revert_accent does not. I put the error > messages in the file. Can anybody tell me why > > document.body[i] = unicodedata.normalize("NFKD", document.body[i]) By default the file stream returns a string when reading a file. This will change in python 3.0 where all strings will be unicode. A shortcut now is to transform every line when reading to unicode in line 194 of LyX.py line = unicode(trim_eol(line)) This is just a guess but it should be enough for this. > does not work? > > If you want to try this, use the attached test file (don't save it with LyX > if you want to test convert_accent, it is hand crafted). > > Georg -- José Abílio
Re: python help needed
On Tue, Jan 09, 2007 at 11:23:52PM +0100, Enrico Forestieri wrote: > On Tue, Jan 09, 2007 at 10:25:15PM +0100, Georg Baum wrote: > > Am Dienstag, 9. Januar 2007 22:19 schrieb Enrico Forestieri: > > > > > No, I didn't try your patch. > > > > That does not help :-( Your script works for me, too. The strange thing is > > that the type of document.body[i] is neither a normal string nor a unicode > > string. At least the error messages seem to suggest that. > > I was compiling. Now I tried it. The TypeError is due to this statement: > > unicode(document.body[i], 'utf8') > > I noticed that the error occurs when document.body[i] is empty, but even > after taking care of this it still occurs, so maybe it is due to some > wrong encoding. I am using the following trick to debug, maybe it can > be of help to you as I really don't know what I should expect: I bet the problem are the backslashes... -- Enrico
Re: python help needed
On Tue, Jan 09, 2007 at 10:25:15PM +0100, Georg Baum wrote: > Am Dienstag, 9. Januar 2007 22:19 schrieb Enrico Forestieri: > > > No, I didn't try your patch. > > That does not help :-( Your script works for me, too. The strange thing is > that the type of document.body[i] is neither a normal string nor a unicode > string. At least the error messages seem to suggest that. I was compiling. Now I tried it. The TypeError is due to this statement: unicode(document.body[i], 'utf8') I noticed that the error occurs when document.body[i] is empty, but even after taking care of this it still occurs, so maybe it is due to some wrong encoding. I am using the following trick to debug, maybe it can be of help to you as I really don't know what I should expect: import os ... for i in range(numberoflines): if (document.body[i] == ''): continue os.system(r'zenity --info --text="(%s)"' % document.body[i]) unistring = unicode(document.body[i], 'utf8') result = unicodedata.normalize("NFKD", unistring) document.body[i] = result.encode('utf8') ... -- Enrico
Re: python help needed
Am Dienstag, 9. Januar 2007 22:19 schrieb Enrico Forestieri: > No, I didn't try your patch. That does not help :-( Your script works for me, too. The strange thing is that the type of document.body[i] is neither a normal string nor a unicode string. At least the error messages seem to suggest that. Georg
Re: python help needed
On Tue, Jan 09, 2007 at 09:57:12PM +0100, Georg Baum wrote: > Am Dienstag, 9. Januar 2007 21:42 schrieb Enrico Forestieri: > > On Tue, Jan 09, 2007 at 07:46:47PM +0100, Georg Baum wrote: > > > José or any other python expert, I need your help. The attached patch > is > > > the lyx2lyx part of the "getting rid of InsetLaTeXAccent" patch. > > > convert_accent works well, but revert_accent does not. I put the error > > > messages in the file. Can anybody tell me why > > > > > > document.body[i] = unicodedata.normalize("NFKD", document.body[i]) > > > > > > does not work? > > > > result = unicodedata.normalize("NFKD", > unicode(utf8encodedstring, 'utf8')) > > > > works fine here. > > How edid you set utf8encodedstring? I used the attached script. > Is that with my test document (first converted to 257 and then back)? No, I didn't try your patch. > What python version? I use 2.4.4. Works with python 2.3.3 on solaris and 2.4.3 on cygwin. -- Enrico #!/usr/bin/env python # -*- coding: utf-8 -*- import unicodedata result = unicodedata.normalize("NFKD", unicode("olà", 'utf8'))
Re: python help needed
Am Dienstag, 9. Januar 2007 21:42 schrieb Enrico Forestieri: > On Tue, Jan 09, 2007 at 07:46:47PM +0100, Georg Baum wrote: > > José or any other python expert, I need your help. The attached patch is > > the lyx2lyx part of the "getting rid of InsetLaTeXAccent" patch. > > convert_accent works well, but revert_accent does not. I put the error > > messages in the file. Can anybody tell me why > > > > document.body[i] = unicodedata.normalize("NFKD", document.body[i]) > > > > does not work? > > result = unicodedata.normalize("NFKD", unicode(utf8encodedstring, 'utf8')) > > works fine here. How edid you set utf8encodedstring? Is that with my test document (first converted to 257 and then back)? What python version? I use 2.4.4. Georg
Re: python help needed
On Tue, Jan 09, 2007 at 07:46:47PM +0100, Georg Baum wrote: > José or any other python expert, I need your help. The attached patch is > the lyx2lyx part of the "getting rid of InsetLaTeXAccent" patch. > convert_accent works well, but revert_accent does not. I put the error > messages in the file. Can anybody tell me why > > document.body[i] = unicodedata.normalize("NFKD", document.body[i]) > > does not work? result = unicodedata.normalize("NFKD", unicode(utf8encodedstring, 'utf8')) works fine here. -- Enrico
python help needed
José or any other python expert, I need your help. The attached patch is the lyx2lyx part of the "getting rid of InsetLaTeXAccent" patch. convert_accent works well, but revert_accent does not. I put the error messages in the file. Can anybody tell me why document.body[i] = unicodedata.normalize("NFKD", document.body[i]) does not work? If you want to try this, use the attached test file (don't save it with LyX if you want to test convert_accent, it is hand crafted). Georg latexaccent-all.lyx Description: application/lyx Index: lib/lyx2lyx/LyX.py === --- lib/lyx2lyx/LyX.py (Revision 16629) +++ lib/lyx2lyx/LyX.py (Arbeitskopie) @@ -73,7 +73,7 @@ format_relation = [("0_06",[200], ge ("1_2", [220], generate_minor_versions("1.2" , 4)), ("1_3", [221], generate_minor_versions("1.3" , 7)), ("1_4", range(222,246), generate_minor_versions("1.4" , 3)), - ("1_5", range(246,257), generate_minor_versions("1.5" , 0))] + ("1_5", range(246,258), generate_minor_versions("1.5" , 0))] def formats_list(): Index: lib/lyx2lyx/lyx_1_5.py === --- lib/lyx2lyx/lyx_1_5.py (Revision 16629) +++ lib/lyx2lyx/lyx_1_5.py (Arbeitskopie) @@ -20,7 +20,9 @@ """ Convert files to the file format generated by lyx 1.5""" import re -from parser_tools import find_token, find_token_exact, find_tokens, find_end_of, get_value +import unicodedata + +from parser_tools import find_re, find_token, find_token_exact, find_tokens, find_end_of, get_value from LyX import get_encoding @@ -719,6 +721,167 @@ def revert_encodings(document): document.inputencoding = get_value(document.header, "\\inputencoding", 0) +accent_map = { +"`" : 0x0309, # grave +"'" : 0x0301, # acute +"^" : 0x0302, # circumflex +"~" : 0x0303, # tilde +"=" : 0x0304, # macron +"u" : 0x0306, # breve +"." : 0x0307, # dot above +"\"": 0x0308, # diaresis +"r" : 0x030a, # ring above +"H" : 0x030b, # double acute +"v" : 0x030c, # caron +"b" : 0x0320, # minus sign below +"d" : 0x0323, # dot below +"c" : 0x0327, # cedilla +"k" : 0x0328, # ogonek +"t" : 0x0361 # tie +} + + +special_accent_map = { +'i' : 0x0131, # dotless i +'j' : 0x0237, # dotless j +'l' : 0x0142, # l with stroke +'L' : 0x0141, # L with stroke +} + +def _convert_accent(type, char): +if char == '': +if type in special_accent_map: +return unichr(special_accent_map[type]) +# a missing char is treated as space by LyX +char = ' ' +if (len(char) > 1): +# We can only convert accents on a single char +return '' +# \i and \j +if char[0] == "\\": +char = char[1:] +a = accent_map.get(type) +if a: +return unicodedata.normalize("NFKC", "%s%s" % (char, unichr(a))) +return '' + + +def convert_ertbackslash(body, i, ert, default_layout): +r""" --- +Convert backslashes and '\n' into valid ERT code, append the converted +text to body[i] and return the (maybe incremented) line index i""" + +for c in ert: +if c == '\\': +body[i] = body[i] + '\\backslash ' +i = i + 1 +body.insert(i, '') +elif c == '\n': +body[i+1:i+1] = ['\\end_layout', '', '\\begin_layout %s' % default_layout, ''] +i = i + 4 +else: +body[i] = body[i] + c +return i + + +def convert_accent(document): +# The following forms are supported by LyX: +# '\i \"{a}' (standard form, as written by LyX) +# '\i \"{ }' (standard form, as written by LyX if the accented char is a space) +# '\i \"{}' (also accepted if the accented char is a space) +# '\i \" a' (also accepted) +# '\i \"'(also accepted) +re_wholeinset = re.compile(r'^(.*)(\\i\s+)(.*)$') +re_contents = re.compile(r'^([^\s{]+)(.*)$') +re_accentedcontents = re.compile(r'^\s*{?([^{}]*)}?\s*$') +i = 0 +while 1: +i = find_re(document.body, re_wholeinset, i) +if i == -1: +return +match = re_wholeinset.match(document.body[i]) +prefix = match.group(1) +contents = match.group(3).strip() +match = re_contents.match(contents) +if match: +# Strip first char (always \) +accent = match.group(1)[1:] +accented_contents = match.group(2).strip() +match = re_accentedcontents.match(accented_contents) +accented_char = match.group(1).strip() +converted = _convert_accent(accent, accented_char) +if converted == '': +contents = '%s{%s}' % (accent, accented_char), +else: +document.body[i] =
Re: python help needed for bug in lyxpreview2ppm.py
Angus Leeming wrote: > That is indeed a problem. We can't quote the first word. > > I think that the thing to do here is to split the full path to the > executable into "basename" and "dirname" parts, to add the "dirname" to > the PATH environment variable (if it's not there already) and to execute > the command as simply > gswin32c.exe foo bar "C:\Program Files\LyX\~\blabla.ps" > > The attached patch seems to do the trick. Please test! Actually, the executable is found only if it's in the PATH already. There's no need for us to manipulate the PATH further. Try this patch instead. -- AngusIndex: lib/scripts/lyxpreview2ppm.py === RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/scripts/Attic/lyxpreview2ppm.py,v retrieving revision 1.1.2.7 diff -u -p -r1.1.2.7 lyxpreview2ppm.py --- lib/scripts/lyxpreview2ppm.py 16 Jun 2005 13:15:11 - 1.1.2.7 +++ lib/scripts/lyxpreview2ppm.py 8 Dec 2005 00:13:02 - @@ -93,7 +93,9 @@ def find_exe(candidates, path): full_path = os.path.join(directory, prog) if os.access(full_path, os.X_OK): -return full_path +# The thing is in the PATH already (or we wouldn't +# have found it. Need just the basename. +return os.path.basename(full_path) return None
Re: python help needed for bug in lyxpreview2ppm.py
On Wednesday 07 December 2005 23:20, Uwe Stöhr wrote: > I investigated a bit and the problem seems to be the call of gs itself: > > The blabla.ps generated by Instant preview can be in a path with spaces > and will work as long as the gswin32c.exe isn't in a path with spaces. > > So it seems that gs is somewhere called together with its path, e.g. > > C:\Program Files\LyX\etc\Ghostscript\bin\gswin32c.exe -dNOPAUSE -dBATCH > -dSAFER -sDEVICE=pnmraw -sOutputFile="C:\Program > Files\LyX\~\blabla%d.ppm" -dGraphicsAlphaBit=XXX -dTextAlphaBits=XXX > rYYY "C:\Program Files\LyX\~\blabla.ps" That is indeed a problem. We can't quote the first word. I think that the thing to do here is to split the full path to the executable into "basename" and "dirname" parts, to add the "dirname" to the PATH environment variable (if it's not there already) and to execute the command as simply gswin32c.exe foo bar "C:\Program Files\LyX\~\blabla.ps" The attached patch seems to do the trick. Please test! Regards, Angus Index: lib/scripts/lyxpreview2ppm.py === RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/scripts/Attic/lyxpreview2ppm.py,v retrieving revision 1.1.2.7 diff -u -p -r1.1.2.7 lyxpreview2ppm.py --- lib/scripts/lyxpreview2ppm.py 16 Jun 2005 13:15:11 - 1.1.2.7 +++ lib/scripts/lyxpreview2ppm.py 8 Dec 2005 00:00:55 - @@ -84,6 +84,17 @@ def error(message): sys.exit(1) +def prepend_if_not_present(list, candidate): +found_it = 0 +for elem in list: +if elem == candidate: +found_it = 1 +break + +if not found_it: +list[0:0] = [ candidate ] + + def find_exe(candidates, path): for prog in candidates: for directory in path: @@ -93,7 +104,8 @@ def find_exe(candidates, path): full_path = os.path.join(directory, prog) if os.access(full_path, os.X_OK): -return full_path +prepend_if_not_present(path, os.path.dirname(full_path)) +return os.path.basename(full_path) return None @@ -339,6 +351,10 @@ def main(argv): dvips = find_exe_or_terminate(["dvips"], path) gs = find_exe_or_terminate(["gswin32c", "gs"], path) pnmcrop = find_exe(["pnmcrop"], path) + +# Update the PATH environment variable to include any additions +# to path. +os.environ['PATH'] = os.pathsep.join(path) # Compile the latex file. latex_call = '%s "%s"' % (latex, latex_file)
Re: python help needed for bug in lyxpreview2ppm.py
Angus Leeming wrote: I either don't understand python nor do I know who wrote the lyxpreview2ppm.py-script. Then perhaps you should read line 8 of this script? Oh how embarrassing. Maybe I'm blind but everything appears to be quoted correctly to me. The lines below generate a string, gs_call in which all paths are certainly quoted. Something like: gswin32c.exe -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pnmraw -sOutputFile="C: \Program Files\LyX\~\blabla%d.ppm" -dGraphicsAlphaBit=XXX -dTextAlphaBits=XXX rYYY "C:\Program Files\LyX\~\blabla.ps" I investigated a bit and the problem seems to be the call of gs itself: The blabla.ps generated by Instant preview can be in a path with spaces and will work as long as the gswin32c.exe isn't in a path with spaces. So it seems that gs is somewhere called together with its path, e.g. C:\Program Files\LyX\etc\Ghostscript\bin\gswin32c.exe -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pnmraw -sOutputFile="C:\Program Files\LyX\~\blabla%d.ppm" -dGraphicsAlphaBit=XXX -dTextAlphaBits=XXX rYYY "C:\Program Files\LyX\~\blabla.ps" But that's only a guess. regards Uwe
Re: python help needed for bug in lyxpreview2ppm.py
On Wednesday 07 December 2005 22:52, you wrote: > Hello developers, > > I just realized a bug in lyxpreview2ppm-py that prevents a working > Instant preview when LyX is installed in a path with spces. > > The problem ist the following: > > When LyX is installed in e.g. C:\Program Files\LyX Ghostscript is called > by lyxpreview2ppm as > > gswin32c.exe C:\Program Files\LyX\~\blabla.ps > > What we need is the following: > > gswin32c.exe "C:\Program Files\LyX\~\blabla.ps" > > simply putting the path to the file in quotes. > > I either don't understand python nor do I know who wrote the > lyxpreview2ppm.py-script. Then perhaps you should read line 8 of this script? > Could somebody have a look at it and send me a > patch so that quotes are always around the filename? Maybe I'm blind but everything appears to be quoted correctly to me. The lines below generate a string, gs_call in which all paths are certainly quoted. gs_call = '%s -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pnmraw ' \ '-sOutputFile="%s%%d.ppm" ' \ '-dGraphicsAlphaBit=%d -dTextAlphaBits=%d ' \ '-r%f "%s"' \ % (gs, latex_file_re.sub("", latex_file), \ alpha, alpha, resolution, ps_file) If you were to add print gs_call immediately afterwards, you'd see the resulting string output to the console. Something like: gswin32c.exe -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pnmraw -sOutputFile="C: \Program Files\LyX\~\blabla%d.ppm" -dGraphicsAlphaBit=XXX -dTextAlphaBits=XXX rYYY "C:\Program Files\LyX\~\blabla.ps" for some integer XXX and YYY. Maybe the '\' directory separators need to be escaped? Angus
python help needed for bug in lyxpreview2ppm.py
Hello developers, I just realized a bug in lyxpreview2ppm-py that prevents a working Instant preview when LyX is installed in a path with spces. The problem ist the following: When LyX is installed in e.g. C:\Program Files\LyX Ghostscript is called by lyxpreview2ppm as gswin32c.exe C:\Program Files\LyX\~\blabla.ps What we need is the following: gswin32c.exe "C:\Program Files\LyX\~\blabla.ps" simply putting the path to the file in quotes. I either don't understand python nor do I know who wrote the lyxpreview2ppm.py-script. Could somebody have a look at it and send me a patch so that quotes are always around the filename? Many thanks in advance and regards Uwe p.s. I'm off by now for the next week but I'll collect all emails.
Re: Python help needed ;-)
Jose' Matos wrote: > On Wednesday 04 June 2003 13:45, Angus Leeming wrote: >> >> Not quite. If the second ExternalInset is of Template "Date" (no >> filename) then the result is >> \begin_inset External >> template Date >> filename taulogo.png >> >> where taulogo.png is filename from the first ExternalInset. >> >> Is there a filename.erase() or something? > > Now if the filename is empty that field doesn't appear, ok? Correct. I think that the increment of 'i' should differ in the two cases though. The snippet below works perfectly. Many thanks for your help. def convert_external(lines): external_rexp = re.compile(r'\\begin_inset External ([^,]*),"([^"]*)",') top = "\\begin_inset External" i = 0 while 1: i = find_token(lines, top, i) if i == -1: break look = external_rexp.search(lines[i]) args = ['',''] if look: args[0] = look.group(1) args[1] = look.group(2) #FIXME: if the previous search fails then warn template = "\ttemplate " + args[0] if args[1]: filename = "\tfilename " + args[1] lines[i:i+1] = [top, template, filename] i=i+2 else: lines[i:i+1] = [top, template] i = i + 1 -- Angus
Re: Python help needed ;-)
On Wednesday 04 June 2003 13:45, Angus Leeming wrote: > > Not quite. If the second ExternalInset is of Template "Date" (no filename) > then the result is > \begin_inset External > template Date > filename taulogo.png > > where taulogo.png is filename from the first ExternalInset. > > Is there a filename.erase() or something? Now if the filename is empty that field doesn't appear, ok? def convert_external(lines): external_rexp = re.compile(r'\\begin_inset External (.*),"(.*)",') i = 0 while 1: i = find_token(lines, "\\begin_inset External", i) if i == -1: break look = external_rexp.search(lines[i]) top = "\\begin_inset External" args = ['',''] if look: args[0] = look.group(1) args[1] = look.group(2) #FIXME: if the previous search fails then warn template = "\ttemplate " + args[0] if args[1]: filename = "\tfilename " + args[1] lines[i:i+1] = [top, template, filename] else: lines[i:i+1] = [top, template] i = i + 1 -- José Abílio
Re: Python help needed ;-)
Jose' Matos wrote: > On Wednesday 04 June 2003 13:29, Angus Leeming wrote: >> [snip...] >> >> Thanks José. Thanks Dekel. >> >> I amalgamated your suggestions. Attached. >> >> It works fine, but I have a couple of (three) questions: > > def convert_external(lines): > external_rexp = re.compile(r'\\begin_inset External (.*),"(.*)",') > i = 0 > while 1: > i = find_token(lines, "\\begin_inset External", i) > if i == -1: > break > look = external_rexp.search(lines[i]) > top = "\\begin_inset External" > args = ['',''] > if look: > args[0] = look.group(1) > args[1] = look.group(2) > #FIXME: if the previous search fails then warn > template = "\ttemplate " + args[0] > if args[1]: > filename = "\tfilename " + args[1] > lines[i:i+1] = [top, template, filename] > i = i + 1 Not quite. If the second ExternalInset is of Template "Date" (no filename) then the result is \begin_inset External template Date filename taulogo.png where taulogo.png is filename from the first ExternalInset. Is there a filename.erase() or something? -- Angus
Re: Python help needed ;-)
On Wednesday 04 June 2003 13:29, Angus Leeming wrote: > [snip...] > > Thanks José. Thanks Dekel. > > I amalgamated your suggestions. Attached. > > It works fine, but I have a couple of (three) questions: def convert_external(lines): external_rexp = re.compile(r'\\begin_inset External (.*),"(.*)",') i = 0 while 1: i = find_token(lines, "\\begin_inset External", i) if i == -1: break look = external_rexp.search(lines[i]) top = "\\begin_inset External" args = ['',''] if look: args[0] = look.group(1) args[1] = look.group(2) #FIXME: if the previous search fails then warn template = "\ttemplate " + args[0] if args[1]: filename = "\tfilename " + args[1] lines[i:i+1] = [top, template, filename] i = i + 1 > 1. Can I add the header variable into the expression searched by the regex > engine? Rather than write it out again. Would be more elegant. Look bellow. > 2. In sed I would write "(.*)" as "\([^"]*\)". Ie include everthing that is > not a '"' rather than include everything. > > It is much more efficient in sed. Is the same not true in python? If so, > what is the syntax? Honestly I don't even think about efficiency here, but yes I can do the same. > 3. Ideally I would not output the filename if it is empty (as occurs with > the Date template. How to do that? I did that also above, the test will suceed only if the string is not empty. Notice that in python " and ' are indentical for string containers (this is different from Perl). So if you don't want to escape those quotes use '. -- José Abílio
Re: Python help needed ;-)
Jose' Matos wrote: >> Could someone write the 5 lines of code? Plase? > > def convert_external(lines): [snip...] Thanks José. Thanks Dekel. I amalgamated your suggestions. Attached. It works fine, but I have a couple of (three) questions: 1. Can I add the header variable into the expression searched by the regex engine? Rather than write it out again. Would be more elegant. 2. In sed I would write "(.*)" as "\([^"]*\)". Ie include everthing that is not a '"' rather than include everything. It is much more efficient in sed. Is the same not true in python? If so, what is the syntax? 3. Ideally I would not output the filename if it is empty (as occurs with the Date template. How to do that? def convert_external(lines): header="\\begin_inset External" i = 0 while 1: i = find_token(lines, header, i) if i == -1: break mo = re.search(r'\\begin_inset External (.*),"(.*)",', lines[i]) if mo: template = "\ttemplate " + mo.group(1) filename = "\tfilename \"" + mo.group(2) + "\"" lines[i:i+1] = [header, template, filename] i = i + 1 -- Angus? lib/reLyX-safe Index: lib/ChangeLog === RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/ChangeLog,v retrieving revision 1.447 diff -u -p -r1.447 ChangeLog --- lib/ChangeLog 4 Jun 2003 09:16:28 - 1.447 +++ lib/ChangeLog 4 Jun 2003 11:21:04 - @@ -1,3 +1,9 @@ +2003-06-04 Angus Leeming <[EMAIL PROTECTED]> + + * lyx2lyx/lyx2lyx: bump the output format to 224. + * lyx2lyx/lyxconvert_221.py (convert_external): new function. + An amalgamation of suggestions from José Matos and Dekel Tsur. + 2003-06-03 Angus Leeming <[EMAIL PROTECTED]> * external_templates: modify the templates to use the converter" mechanism. Index: lib/lyx2lyx/lyx2lyx === RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx2lyx,v retrieving revision 1.8 diff -u -p -r1.8 lyx2lyx --- lib/lyx2lyx/lyx2lyx 14 Mar 2003 13:37:34 - 1.8 +++ lib/lyx2lyx/lyx2lyx 4 Jun 2003 11:21:06 - @@ -37,7 +37,7 @@ opt.quiet = 0 format = re.compile(r"(\d)[\.,]?(\d\d)") fileformat = re.compile(r"\\lyxformat\s*(\S*)") -lst_ft = ["210", "215", "216", "217", "218", "220", "221", "223"] +lst_ft = ["210", "215", "216", "217", "218", "220", "221", "224"] def usage(): print """Usage: lyx2lyx [options] file1 Index: lib/lyx2lyx/lyxconvert_221.py === RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyxconvert_221.py,v retrieving revision 1.5 diff -u -p -r1.5 lyxconvert_221.py --- lib/lyx2lyx/lyxconvert_221.py 2 Jun 2003 14:16:17 - 1.5 +++ lib/lyx2lyx/lyxconvert_221.py 4 Jun 2003 11:21:06 - @@ -16,6 +16,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import string +import re from parser_tools import find_token def add_end(header): @@ -38,11 +39,26 @@ def remove_insetparent(lines): break del lines[i:i+3] +def convert_external(lines): +header="\\begin_inset External" +i = 0 +while 1: +i = find_token(lines, header, i) +if i == -1: +break +mo = re.search(r'\\begin_inset External (.*),"(.*)",', lines[i]) +if mo: +template = "\ttemplate " + mo.group(1) +filename = "\tfilename \"" + mo.group(2) + "\"" +lines[i:i+1] = [header, template, filename] +i = i + 1 + def convert(header, body): add_end(header) convert_spaces(body) convert_bibtex(body) remove_insetparent(body) +convert_external(body) if __name__ == "__main__": pass
Re: Python help needed ;-)
On Wed, Jun 04, 2003 at 11:18:09AM +0100, Jose' Matos wrote: > > I point the answer, use split. > > > Could someone write the 5 lines of code? Plase? > > def convert_external(lines): > i = 0 > while 1: > i = find_token(lines, "\\begin_inset External", i) > if i == -1: > break > top = "\\begin_inset External" > args = string.split(lines[i][len(top)+1:],',') > template = "\ttemplate " + args[0] > filename = "\tfilename " + args[1] > lines[i:i+1] = [top, template, filename] > i = i + 1 This will fail if the filename contains ','. It is probably better to use regular expressions (see my other mail).
Re: Python help needed ;-)
On Wednesday 04 June 2003 11:33, Angus Leeming wrote: > I want to add a module to lyxconvert_221.py to change this: > > \begin_inset External RasterImage,"taulogo.png","" > > \end_inset > > to this > > \begin_inset External > template RasterImage > filename taulogo.png > > \end_inset > > throwing away the final arg (here "", more generally "") that holds > the parameters variable. I guess that we could retain the filename within > quotes as LyXLeX will handle that. > > Trouble is, I don't know how to split the line into its constituent parts. I point the answer, use split. > Could someone write the 5 lines of code? Plase? def convert_external(lines): i = 0 while 1: i = find_token(lines, "\\begin_inset External", i) if i == -1: break top = "\\begin_inset External" args = string.split(lines[i][len(top)+1:],',') template = "\ttemplate " + args[0] filename = "\tfilename " + args[1] lines[i:i+1] = [top, template, filename] i = i + 1 I'm not even sure this runs, if you send me a file I will teste this code for you. :-) -- José Abílio
Re: Python help needed ;-)
On Wed, Jun 04, 2003 at 10:33:02AM +, Angus Leeming wrote: > I want to add a module to lyxconvert_221.py to change this: > > \begin_inset External RasterImage,"taulogo.png","" > > \end_inset > > to this > > \begin_inset External > template RasterImage > filename taulogo.png > > \end_inset > > throwing away the final arg (here "", more generally "") that holds > the parameters variable. I guess that we could retain the filename within > quotes as LyXLeX will handle that. > > Trouble is, I don't know how to split the line into its constituent parts. import re mo = re.search(r'\\begin_inset External (.*),"(.*)",', a) if mo: print "template", mo.group(1) print "filename", mo.group(2) This code will fail if the filename contains the char '"' (how does the lyx file look in that case ? )
Re: Python help needed ;-)
On Wed, Jun 04, 2003 at 10:33:02AM +, Angus Leeming wrote: > throwing away the final arg (here "", more generally "") that holds > the parameters variable. I guess that we could retain the filename within > quotes as LyXLeX will handle that. We should, as this may contain spaces, shouldn't we? > Could someone write the 5 lines of code? Plase? I don't speak Python... Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson or B. Franklin or both...)
Python help needed ;-)
I want to add a module to lyxconvert_221.py to change this: \begin_inset External RasterImage,"taulogo.png","" \end_inset to this \begin_inset External template RasterImage filename taulogo.png \end_inset throwing away the final arg (here "", more generally "") that holds the parameters variable. I guess that we could retain the filename within quotes as LyXLeX will handle that. Trouble is, I don't know how to split the line into its constituent parts. Could someone write the 5 lines of code? Plase? -- Angus