Example #1
0
def set_elsevier_format():
    from pylatex.pybib import JournalArticle, ComputerProgram, Book, set, Record, BookSection

    Record.setDefaults()

    #entry JCP guidelines
    def journal_bibitem(r):
        format = "%s, %s, %s (%s), p. %s." % (r['authors'], r['journal'], r['volume'], r['year'], r['pages'])
        return format
    JournalArticle.bibitem = journal_bibitem
    set('authors', JournalArticle, delim = ',', lastname = False)
    set('volume', JournalArticle, style = 'bold')
    set('pages', JournalArticle, lastpage = False) #no style modification
    set('year', JournalArticle)
    set('journal', JournalArticle)

    def program_bibitem(r):
        format = "%s. %s." % (r['authors'], r['title'])

        year = r['year']
        if year:
            format += " %s." % year
        
        publisher = r['publisher']
        if publisher:
            format += " %s." % publisher

        url = r['url']
        if url:
            format += " %s." % url

        return format
    ComputerProgram.bibitem = program_bibitem
    set('title', ComputerProgram) #defaults are fine
    set('year', ComputerProgram)
    set('authors', ComputerProgram, delim = ',', lastname = False)
    set('publisher', ComputerProgram) #defaults are fine
    set('url', ComputerProgram) #defaults are fine


    def book_bibitem(r):
        format = "%s, %s." % (r['authors'], r['title'])

        editors = r['editors']
        if editors:
            format += " edited by %s." % editors

        format += " (%s, %s, %s)." % (r['publisher'], r['city'], r['year'])

        return format
    Book.bibitem = book_bibitem
    set('title', Book, style='italic') #defaults are fine
    set('year', Book)
    set('edition', Book)
    set('authors', Book, delim = ',', lastname = False)
    set('editors', Book, delim = ',', lastname = False)
    set('publisher', Book) #defaults are fine
    set('city', Book) #defaults are fine

    def book_section_bibitem(r):
        format = "%s, `%s' in \\textit{%s}" % (r['authors'], r['title'], r['booktitle'])

        editors = r['editors']
        if editors:
            format += " edited by %s." % editors

        format += " (%s, %s, %s)." % (r['publisher'], r['city'], r['year'])
        return format
    BookSection.bibitem = book_section_bibitem
    set('authors', BookSection, delim = ',', lastname = False)
    set('editors', BookSection, delim = ',', lastname = False)
    set('year',    BookSection)
    set('title',   BookSection) #defaults are fine
    set('booktitle',   BookSection) #defaults are fine
    set('label',   BookSection) #defaults are fine
    set('publisher',   BookSection) #defaults are fine
    set('city',   BookSection) #defaults are fine
Example #2
0
def loadCitation(cword):
    import os

    import pyvim.pyvim as vim
    import re
    import pygtk
    import gtk
    import os.path

    from pylatex.pybib import Record

    Record.unsetFormat()
    Record.setDefaults()

    entries = []
    if "~" in cword:
        cword = "~" + cword.split("~")[-1]

    if "\cite{" in cword:  # we are currently on a citation
        # get the entries within the citation
        innards = re.compile(r"cite[{](.*?)[}]").search(cword).groups()[0].strip()
        if innards:
            entries = map(lambda x: x.strip(), innards.split(","))
        else:
            entries = []
    else:  # no citation, but put one in
        vim.appendAtWord("~\cite{}", ",", ".")
        cword = "~\cite{}"

    # build the citation
    import os.path

    if not hasattr(PyTexGlobals, "bib"):
        # import PyGui
        # filesel = PyGui.FileSelect(os.path.join(os.path.expanduser("~"), "Documents"), setBibliography, main=True)
        # gtk.main()
        from pylatex.pybib import Bibliography

        empty = Bibliography()
        empty.buildRecords(Bibliography.ENDNOTE_XML_LIB)
        setattr(PyTexGlobals, "bib", empty)

    bib = getattr(PyTexGlobals, "bib")
    title = "Reference at line %d" % vim.PyVimGlobals.line
    # title = "test"
    citeobj = Citation(title, bib, entries)

    gtk.gdk.threads_init()
    gtk.gdk.threads_enter()
    gtk.main()
    gtk.gdk.threads_leave()

    # use the citation object to generate the new reference
    entries = citeobj.getEntries()
    labels = []
    for entry in entries:
        labels.append(str(entry.getAttribute("label")))

    newtext = ""
    if labels:
        newtext = "~\cite{%s}" % ",".join(labels)

    vim.replace(cword, newtext)
Example #3
0
def set_cv_format():
    from pylatex.pybib import JournalArticle, ComputerProgram, Book, set, Record, BookSection, Bibliography, RecordObject

    def bibitem(self, key):
        return "\\paper"
    Bibliography.bibitem = bibitem

    RecordObject.sort_criterion = "label"
    RecordObject.reverse_sort = True

    Record.setDefaults()

    def journal_bibitem(r):
        format = """{%s}
        {%s}
        {%s}
        {%s}
        {%s}{%s}{%s}""" % (r['title'], r['doi'], r['authors'], r['journal'], r['volume'], r['pages'], r['year'])
        return format
    JournalArticle.bibitem = journal_bibitem
    set('authors', JournalArticle, delim = ',', lastname = False)
    set('volume', JournalArticle)
    set('pages', JournalArticle, lastpage = False) #no style modification
    set('year', JournalArticle)
    set('journal', JournalArticle)
    set('doi', JournalArticle)

    def program_bibitem(r):
        format = "%s. %s." % (r['authors'], r['title'])

        year = r['year']
        if year:
            format += " %s." % year
        
        publisher = r['publisher']
        if publisher:
            format += " %s." % publisher

        url = r['url']
        if url:
            format += " %s." % url

        return format
    ComputerProgram.bibitem = program_bibitem
    set('title', ComputerProgram) #defaults are fine
    set('year', ComputerProgram)
    set('authors', ComputerProgram, delim = ',', lastname = False)
    set('publisher', ComputerProgram) #defaults are fine
    set('url', ComputerProgram) #defaults are fine


    def book_bibitem(r):
        format = "%s, %s." % (r['authors'], r['title'])

        editors = r['editors']
        if editors:
            format += " edited by %s." % editors

        format += " (%s, %s, %s)." % (r['publisher'], r['city'], r['year'])

        return format
    Book.bibitem = book_bibitem
    set('title', Book, style='italic') #defaults are fine
    set('year', Book)
    set('edition', Book)
    set('authors', Book, delim = ',', lastname = False)
    set('editors', Book, delim = ',', lastname = False)
    set('publisher', Book) #defaults are fine
    set('city', Book) #defaults are fine

    def book_section_bibitem(r):
        format = "%s, `%s' in \\textit{%s}" % (r['authors'], r['title'], r['booktitle'])

        editors = r['editors']
        if editors:
            format += " edited by %s." % editors

        format += " (%s, %s, %s)." % (r['publisher'], r['city'], r['year'])
        return format
    BookSection.bibitem = book_section_bibitem
    set('authors', BookSection, delim = ',', lastname = False)
    set('editors', BookSection, delim = ',', lastname = False)
    set('year',    BookSection)
    set('title',   BookSection) #defaults are fine
    set('booktitle',   BookSection) #defaults are fine
    set('label',   BookSection) #defaults are fine
    set('publisher',   BookSection) #defaults are fine
    set('city',   BookSection) #defaults are fine
Example #4
0
def set_html_format():
    import re
    from pylatex.pybib import JournalArticle, ComputerProgram, Book, set, Record, BookSection, Bibliography, RecordObject

    def bibitem(self, key):
        return ""
    Bibliography.bibitem = bibitem

    RecordObject.sort_criterion = "label"
    RecordObject.reverse_sort = True

    Record.setDefaults()

    def replace_subscript(match):
        text = match.groups()[0]
        return "<sub>%s</sub>" % text

    def journal_bibitem(r):
        title = r['title']
        title = re.sub(r'[$]_[{]?(.*?)[}]?[$]',replace_subscript,title)
        format = """<li><a href=http://dx.doi.org/%s>%s</a><br>
        %s, %s <b>%s</b>, %s (%s).</li>""" % (r['doi'], title, r['authors'], r['journal'], r['volume'], r['pages'], r['year'])
        return format
    JournalArticle.bibitem = journal_bibitem
    set('authors', JournalArticle, delim = ',', lastname = False)
    set('volume', JournalArticle)
    set('pages', JournalArticle, lastpage = False) #no style modification
    set('year', JournalArticle)
    set('journal', JournalArticle)
    set('doi', JournalArticle)

    def program_bibitem(r):
        format = "%s. %s." % (r['authors'], r['title'])

        year = r['year']
        if year:
            format += " %s." % year
        
        publisher = r['publisher']
        if publisher:
            format += " %s." % publisher

        url = r['url']
        if url:
            format += " %s." % url

        return format
    ComputerProgram.bibitem = program_bibitem
    set('title', ComputerProgram) #defaults are fine
    set('year', ComputerProgram)
    set('authors', ComputerProgram, delim = ',', lastname = False)
    set('publisher', ComputerProgram) #defaults are fine
    set('url', ComputerProgram) #defaults are fine


    def book_bibitem(r):
        format = "%s, %s." % (r['authors'], r['title'])

        editors = r['editors']
        if editors:
            format += " edited by %s." % editors

        format += " (%s, %s, %s)." % (r['publisher'], r['city'], r['year'])

        return format
    Book.bibitem = book_bibitem
    set('title', Book, style='italic') #defaults are fine
    set('year', Book)
    set('edition', Book)
    set('authors', Book, delim = ',', lastname = False)
    set('editors', Book, delim = ',', lastname = False)
    set('publisher', Book) #defaults are fine
    set('city', Book) #defaults are fine

    def book_section_bibitem(r):
        format = "%s, `%s' in \\textit{%s}" % (r['authors'], r['title'], r['booktitle'])

        editors = r['editors']
        if editors:
            format += " edited by %s." % editors

        format += " (%s, %s, %s)." % (r['publisher'], r['city'], r['year'])
        return format
    BookSection.bibitem = book_section_bibitem
    set('authors', BookSection, delim = ',', lastname = False)
    set('editors', BookSection, delim = ',', lastname = False)
    set('year',    BookSection)
    set('title',   BookSection) #defaults are fine
    set('booktitle',   BookSection) #defaults are fine
    set('label',   BookSection) #defaults are fine
    set('publisher',   BookSection) #defaults are fine
    set('city',   BookSection) #defaults are fine