can we Protect everything such as $\Xi_{cc}$ in title (do not let underscore becomes \_)

Issue #132 new
Zhan-Wei Liu created an issue

In my bib file, the title is well written as Latex form

@Article{Luo:2003q,
Title = {{Resolving the low mass puzzle of $\Xi_{cc}(2940)^+$}},
Author = {…},

}

With the following command and my own-written formatting-style.py even with Protected() function,

pybtex --style-language python someTexFile

The title in the someTexFile.bbl still becomes

\newblock {Resolving the low mass puzzle of $\Xi\_{cc}(2940)^+$}}.

That is, the underscore “_” becomes “\_”.

How can we do not let that happen and keep everything in title as the original one?

Comments (1)

  1. Zhan-Wei Liu reporter

    How to configure your reference style with pybtex (for beginners). Here I show more details after these days studying.

    1. install pybtex
      pip install pybtex
    2. install setuptools.
      pip install -U setuptools
    3. we configure conf.py .

    from __future__ import unicode_literals
    import codecs
    import latexcodec  # noqa
    from pybtex.backends import BaseBackend
    
    from pybtex.style.formatting.unsrt import Style as UnsrtStyle
    from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle
    from pybtex.richtext import Symbol, Text, Protected, BaseMultipartText
    from pybtex.style.formatting import BaseStyle, toplevel
    from pybtex.style.template import (
        field, first_of, href, join, names, optional, optional_field, sentence,
        tag, together, words, FieldIsMissing
    )
    import re
    
    class CustomStyle(UnsrtStyle):
        default_sorting_style = 'author_year_title'
    
        def get_article_template(self, entry):
            template = toplevel[
               self.format_myeprint(entry),
            ]
            return template
    
        def format_myeprint(self, entry):
            eprint  = self.optField(entry, 'eprint')
            if not eprint:
                return ''
            formatEprint=r'\ttfamily arXiv:%s' % eprint
            if href_YN:
                return r'\href{%s}{%s}' % (r'https://arxiv.org/abs/%s' % eprint, formatEprint )
            else:
                return  formatEprint
    
        def optField(self,entry, which_field):
            supField=''
            for key in entry.fields.keys():
                if which_field.lower()== key.lower():
                    supField=entry.fields[which_field]
            for key in entry.persons.keys():
                if which_field.lower()== key.lower():
                    supField=entry.persons[which_field]
            return supField
    
        def __init__(self, *args, **kwargs):
            super(CustomStyle, self).__init__(*args, **kwargs)
    
    class myBackend(BaseBackend):
        ....
        def format_str(self, str_):
            #return codecs.encode(str_, self.latex_encoding)
            return str_
    
    
    #in an entry, there are three parts: key, fields, and persons
    #entry.fields['journal'] is an ordinary string
    #entry.persons['author'] is an ordinary string
    #entry.key is an ordinary string
    

    4.write setupXX.py file and run the following command only once: python setupXX.py develop
    In setupPR.py, we write

    from setuptools import setup
    
    setup(name='PybtexPR plugins',
        py_modules=['conf'],
        entry_points = {
            'pybtex.style.formatting': 'customPR=conf:CustomStyle',
            'pybtex.backends': 'mybackend=conf:myBackend',
        },
    )
     #the reference style file will be conf.py
     #customPR will be used in the .tex file; 
     #conf:CustomStyle will be defined in conf.py
     #register mybackend to solve the problem I raised
    

    5. In your tex file, add
    \bibliographystyle{customPR}
    \bibliography{someBibFile}

    and run the following command for generating the bbl file for the references:

    pybtex --style-language python -b mybackend texfileName

  2. Log in to comment