Richard Heck a écrit :
On 10/31/2010 06:38 AM, Jean-Pierre Chrétien wrote:
Jean-Pierre Chrétien a écrit :
So do we have an extra \makeatletter somewhere?
Yes, exporting my example file in LaTeX reads:
<cite>
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\AtBeginDocument{\providecommand\secref[1]{\ref{#1}}}
\AtBeginDocument{\providecommand\eqref[1]{\ref{#1}}}
\AtBeginDocument{\providecommand\lemref[1]{\ref{#1}}}
\AtBeginDocument{\providecommand\thmref[1]{\ref{#1}}}
\makeatletter
\...@ifundefined{thmref}
{\def\RSthmtxt{theorem~}\newref{thm}{name = \RSthmtxt}}
{}
\...@ifundefined{lemref}
{\def\RSlemtxt{lemma~}\newref{lem}{name = \RSlemtxt}}
{}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\theoremstyle{plain}
</cite>
Currently refstyle cannot work natively with babel multilingual docs,
encapsulating strings definitions in \adddto\captionsxxxx works, I've
contacted Danie Els about this.
Is there something we can do in the meantime?
I got an anwer from Danie, I was mistaken about the multilingual feature of
refstyle: it works all right (as \def commands are encapsulated in \extras<lang>
commands) if refstyle is loaded *after* babel.
Is it possible to do this in LyX ?
In the meantime, I've found another point which the current patch misses:
part and chap are the prefixes in refstyle, so old refs are replaced by ?? if
the "Use refstyle" box is checked.
I've added to convert_prettyref in lyx-2.0.py the code that you wrote last April
and that I enhanced to convert all prefixes cha and par to chap and part.
I've added a step to deal with \newrefformat commands in the preamble.
Currently my re_newref string works as a command line in the pyton interpreter:
<cite>
$ python
Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re_newref = re.compile(r"\newrefformat\{(\w+)\}\{(\w+)")
>>> m=re_newref.match('\newrefformat{cha}{Chapitre~\ref{#1}}')
>>> print m.group(1)
cha
>>> print m.group(2)
Chapitre
>>>
</cite>
but not in the convert_prettyref code (beware of the extra newlines added by my
mailer, I've posted the corresponding patch on bug #6609 anyway):
<cite>
def convert_prettyref(document):
" Converts prettyref references to neutral formatted refs, updates part and
chapter prefixes "
re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
re_lab = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
re_newref = re.compile(r"\newrefformat\{(\w+)\}\{(\w+)")
# Note: step 1, \newrefformat part: and chap: susbtitutions for par:
and cha:
i = 0
while True:
i = find_token(document.preamble, "\\newrefformat{", i)
result=document.preamble[i]
document.warning("Found document.preamble[i]" + result)
if i == -1:
break
m = re_newref.match(result)
if m:
prefix = m.group(1)
remain = m.group(2)
document.warning("Found " + prefix + " " + result)
if prefix == "cha":
prefix = "chap"
elif prefix == "par":
prefix = "part"
document.preamble[i] = "\\newrefformat" + "\{" + prefix + "\}"
+ remain
i = i + 1
# Note: step 2, reference part: and chap: susbtitutions for par:
and cha:
i = 0
while True:
i = find_token(document.body, "\\begin_inset CommandInset ref", i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: No end of InsetRef")
i += 1
continue
i += 1
k = find_token(document.body, "reference", i)
if k == -1 or k > j:
i = j + 1
continue
m = re_ref.match(document.body[k])
if m:
prefix = m.group(1)
suffix = m.group(2)
if prefix == "cha":
prefix = "chap"
elif prefix == "par":
prefix = "part"
document.body[k] = "reference" + " \"" + prefix + ":" + suffix
+ "\""
i = j + 1
# Note: step 3, label part: and chap: susbtitutions for par: and
cha:
i = 0
while True:
i = find_token(document.body, "\\begin_inset CommandInset label", i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: No end of InsetRef")
i += 1
continue
i += 1
k = find_token(document.body, "name", i)
if k == -1 or k > j:
i = j + 1
continue
m = re_lab.match(document.body[k])
if m:
prefix = m.group(1)
suffix = m.group(2)
if prefix == "cha":
prefix = "chap"
elif prefix == "par":
prefix = "part"
document.body[k] = "name" + " \"" + prefix + ":" + suffix + "\""
i = j + 1
# Note: step 4, prettyref to neutral
i = 0
while True:
i = find_token(document.body, "\\begin_inset CommandInset ref",
i)
if i == -1:
break
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed LyX document: No end of
InsetRef!")
i += 1
continue
k = find_token(document.body, "LatexCommand prettyref", i)
if k != -1 and k < j:
document.body[k] = "LatexCommand formatted"
i = j + 1
document.header.insert(-1, "\\use_refstyle 0")
</cite>
I'm not a Python guru, so I hope you can find the right hack.
I've not written the reversion in revert_refstyle, is it necessary ? (maybe for
file sharing ?).
--
Jean-Pierre