- edited description
- changed status to resolved
Should not latex decode some fields
Issue #86
resolved
When formatting a bibliography like this
style = pybtex.stylce.formatting.plain.Style
style.format_entries(bib_data.entries.values())
it will fail on “url” fields where the URL contains a percent sign. The current version of latexcodec (1.0.3) raises an exception, the upcoming version (1.0.4) will cut off everything behind the percent sign because it is treated as a comment.
Latex decoding should not be applied to some fields like URL (not sure what other fields). My workaround at the moment is:
from pybtex.style.template import FieldIsMissing, href, join, node, words
@node
def raw_field(children, data, name, apply_func=None):
"""Return the raw contens of the bibliography entry field.
This function does not decode special LaTeX characters."""
assert not children
try:
field = data.fields[name]
except KeyError:
raise FieldIsMissing(name, data)
else:
if apply_func:
field = applay_func(field)
return field
class NonURLDecodingPlainStyle(pybtex.style.formatting.plain.Style):
"""Plain text pybtex style which does not attempt to latex decode URLs."""
def format_url(self, e):
return words [
'URL:',
href [
raw_field('url'),
join(' ') [
raw_field('url')
]
]
]
style = NonURLDecodingPlainStyle()
Comments (1)
-
- Log in to comment
Fixed in f79b6ad, thanks.