Skip to content
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

Open
moewew opened this issue Oct 30, 2018 · 3 comments
Open

Variables in special-templates #15

moewew opened this issue Oct 30, 2018 · 3 comments

Comments

@moewew
Copy link

moewew commented Oct 30, 2018

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
Lenz (???)//Lenz, Christoph. 2017–2018 from 2017-07-04/2018-01-05

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.)


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.

@nzhagen
Copy link
Owner

nzhagen commented Oct 31, 2018 via email

@nzhagen
Copy link
Owner

nzhagen commented Nov 3, 2018 via email

@moewew
Copy link
Author

moewew commented Nov 3, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants