-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variables in special-templates #15
Comments
Thanks for letting me know about the issue! I'm currently on travel and
don't have a good setup for testing your code, but I will give it a try
tomorrow morning when I get back to my desk at work and let you know as
soon as I can. Sorry for the delay....
- Nathan
…On Tue, Oct 30, 2018 at 4:41 PM moewew ***@***.***> wrote:
While I was looking at https://tex.stackexchange.com/q/457230/35864 on
TeX.SX I was trying to get user-defined variables from VARIABLES working
in a SPECIAL-TEMPLATE block and failed to do so.
Consider the following example
\documentclass[11pt, a4papter]{scrartcl}
\usepackage{natbib}
\usepackage{filecontents}
\begin{filecontents*}{dateyear.bst}
TEMPLATES:
electronic = <au>. <dateyear> from <date>
SPECIAL-TEMPLATES:
citelabel = <authorlist.0.last>, <dateyear>
sortkey = <authorlist.0.last><dateyear>
OPTIONS:
allow_scripts = True
namelist_format = last_name_first
use_firstname_initials = False
VARIABLES:
dateyear = parse_date_or_year(entry, options)
DEFINITIONS:
def parse_date_or_year(entry, options):
'''
Parses the ISO 8601 date in the date field or year in year field
'''
if ('date' in entry):
datematch = re.search(r'\A([0-9]{4})(?:-[0-9]{2}){0,2}(?:/([0-9]{4})(?:-[0-9]{2}){0,2})?\Z', entry['date'])
if datematch.group(2):
return(datematch.group(1) + "--" + datematch.group(2))
elif datematch.group(1):
return(datematch.group(1))
elif ('year' in entry):
return(entry['year'])
return(None)
\end{filecontents*}
\begin{filecontents}{\jobname.bib}
@Electronic{Lenz1,
author = {Lenz, Christoph},
institution = {Tages-Anzeiger Online},
date = {2017-07-04/2018-01-05},
title = {Rechenspiele der Armee haben politische Folgen},
url = {https://www.tagesanzeiger.ch/schweiz/standard/rechenspiele-der-armee-haben-politische-folgen/story/19945957},
urldate = {2018-10-16},
}
\end{filecontents}
\begin{document}
\cite{Lenz1}
\bibliographystyle{dateyear}
\bibliography{\jobname}
\end{document}
The output for me is
[image: Lenz (???)//Lenz, Christoph. 2017–2018 from 2017-07-04/2018-01-05]
<https://user-images.githubusercontent.com/6755835/47702995-fefe2c00-dc1e-11e8-9e94-5f542072a033.png>
So my user-defined variable dateyear works very well in TEMPLATES, but
fails to work in SPECIAL-TEMPLATES.
Would it be possible to allow SPECIAL-TEMPLATES to access these variable
definitions as well?
PS: As you can see I'm trying a crude implementation of ISO 8601 parsing
for a date field (similar to what biblatex does). I think this could be
useful as a core feature, so if you like you can additionally read this
issue as a feature request for ISO date parsing. (If you like I can open a
new issue for that feature request to keep things nice and tidy.)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#15>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADVSseAJnS_lzqGCjdji7E54B4XfNVhzks5uqAKfgaJpZM4YBWHw>
.
|
moewew,
I've been working on the issue and I can see what is causing the problem,
but unfortunately the fix is not a simple edit, but something that requires
some careful restructuring. I haven't done much testing of this kind of
freeform defining of variables, and you ran into an issue due to this lack
of testing. The easiest thing would be for me to hard-code a function that
parses an ISO 8601 date into its components. I think I should be able to
get that in this week, and make a start on restructuring the freeform
definitions to avoid the original error you ran into.
- Nathan
…On Wed, Oct 31, 2018 at 12:07 PM N H ***@***.***> wrote:
Thanks for letting me know about the issue! I'm currently on travel and
don't have a good setup for testing your code, but I will give it a try
tomorrow morning when I get back to my desk at work and let you know as
soon as I can. Sorry for the delay....
- Nathan
On Tue, Oct 30, 2018 at 4:41 PM moewew ***@***.***> wrote:
> While I was looking at https://tex.stackexchange.com/q/457230/35864 on
> TeX.SX I was trying to get user-defined variables from VARIABLES working
> in a SPECIAL-TEMPLATE block and failed to do so.
>
> Consider the following example
>
> \documentclass[11pt, a4papter]{scrartcl}
> \usepackage{natbib}
> \usepackage{filecontents}
> \begin{filecontents*}{dateyear.bst}
> TEMPLATES:
> electronic = <au>. <dateyear> from <date>
>
> SPECIAL-TEMPLATES:
> citelabel = <authorlist.0.last>, <dateyear>
> sortkey = <authorlist.0.last><dateyear>
>
>
> OPTIONS:
> allow_scripts = True
> namelist_format = last_name_first
> use_firstname_initials = False
>
>
> VARIABLES:
> dateyear = parse_date_or_year(entry, options)
>
> DEFINITIONS:
> def parse_date_or_year(entry, options):
> '''
> Parses the ISO 8601 date in the date field or year in year field
> '''
>
> if ('date' in entry):
> datematch = re.search(r'\A([0-9]{4})(?:-[0-9]{2}){0,2}(?:/([0-9]{4})(?:-[0-9]{2}){0,2})?\Z', entry['date'])
> if datematch.group(2):
> return(datematch.group(1) + "--" + datematch.group(2))
> elif datematch.group(1):
> return(datematch.group(1))
> elif ('year' in entry):
> return(entry['year'])
>
> return(None)
> \end{filecontents*}
> \begin{filecontents}{\jobname.bib}
> @Electronic{Lenz1,
> author = {Lenz, Christoph},
> institution = {Tages-Anzeiger Online},
> date = {2017-07-04/2018-01-05},
> title = {Rechenspiele der Armee haben politische Folgen},
> url = {https://www.tagesanzeiger.ch/schweiz/standard/rechenspiele-der-armee-haben-politische-folgen/story/19945957},
> urldate = {2018-10-16},
> }
> \end{filecontents}
>
> \begin{document}
> \cite{Lenz1}
> \bibliographystyle{dateyear}
> \bibliography{\jobname}
> \end{document}
>
> The output for me is
> [image: Lenz (???)//Lenz, Christoph. 2017–2018 from 2017-07-04/2018-01-05]
> <https://user-images.githubusercontent.com/6755835/47702995-fefe2c00-dc1e-11e8-9e94-5f542072a033.png>
>
> So my user-defined variable dateyear works very well in TEMPLATES, but
> fails to work in SPECIAL-TEMPLATES.
>
> Would it be possible to allow SPECIAL-TEMPLATES to access these variable
> definitions as well?
>
> PS: As you can see I'm trying a crude implementation of ISO 8601 parsing
> for a date field (similar to what biblatex does). I think this could be
> useful as a core feature, so if you like you can additionally read this
> issue as a feature request for ISO date parsing. (If you like I can open a
> new issue for that feature request to keep things nice and tidy.)
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#15>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ADVSseAJnS_lzqGCjdji7E54B4XfNVhzks5uqAKfgaJpZM4YBWHw>
> .
>
|
Thank you for having a look at this. I think it is a great idea to implement ISO 8601 date parsing natively in Bibulous (I would have asked you to do that even if a fix for the reported issue had been easy). Let me know if I can help with the other issue (probably only testing). Though I should say that I'm not a regular Bibulous user, I only use it when I see the occasional question on TeX.SX, so I can not help with extensive test cases, just with a few ad-hoc things that I thought should work. |
While I was looking at https://tex.stackexchange.com/q/457230/35864 on TeX.SX I was trying to get user-defined variables from
VARIABLES
working in aSPECIAL-TEMPLATE
block and failed to do so.Consider the following example
The output for me is
So my user-defined variable
dateyear
works very well inTEMPLATES
, but fails to work inSPECIAL-TEMPLATES
.Would it be possible to allow
SPECIAL-TEMPLATES
to access these variable definitions as well?PS: As you can see I'm trying a crude implementation of ISO 8601 parsing for a
date
field (similar to whatbiblatex
does). I think this could be useful as a core feature, so if you like you can additionally read this issue as a feature request for ISO date parsing. (If you like I can open a new issue for that feature request to keep things nice and tidy.)I should probably say that I'm using Bibulous 1.3 as downloaded yesterday directly from GitHub (https://github.com/nzhagen/bibulous/tree/5d6b2d11e6f6e9ffa23359777eba69472ff1b49b). Bibulous is running on Python 2.7.15 (I had trouble with Python 3 and gave up) on Windows 10.
The text was updated successfully, but these errors were encountered: