5

I hope that you can help me to get customized labels for my bibliography.
I want to get a specific format for labels in bibliography, using \biblatex; only two characters, alphabetically ordered:

  1. The first character of the author's name.
  2. A number, which is the list for the first character.

I understood that I have to change the \DeclareLabelalphaTemplate; but I don't know how, I'm using this code:

\documentclass[11pt,a4paper]{article}

\usepackage[spanish, es-noshorthands]{babel}

\usepackage{csquotes}
\usepackage[backend=biber,style=alphabetic,backend=biber]{biblatex}
\usepackage{hyperref}
\addbibresource{bib.bib}

\DeclareLabelalphaTemplate{
  \labelelement{
    \field[final]{shorthand}
    \field{label}
    \field[strwidth=1,strside=left,ifnames=1,compound=false]{labelname}
  }
  \labelelement{ %I have to change or add here, I suppose.
    \field[]{}
  }
}

\begin{document}

These are my references, \cite{bael}, \cite{is}, \cite{macgregor}, \cite{morales}, \cite{nationalacademy-joints}, \cite{pfeiffer}.

\printbibliography


\end{document}

This is my bibliography data:

@book{morales,
    author    = {R. Morales},
    title     = {Diseño Estructural Sismorresistente},
    publisher = {Fondo Editorial ICG},
    year      = {2002},
    address   = {Lima},
    pages     = {4-5},
    }

@book{macgregor,
    author    = {J. MacGregor and J. Wight},
    title     = {Reinforced Concrete Mechanics and Design},
    publisher = {Prentice Hall},
    date      = {2011},
    location  = {Upper Saddle River, New Jersey},
    pages     = {71-71},
    }

@report{pfeiffer,
    author    = {Michael J. Pfeiffer, and David Darwin},
    title     = {Joint Design for Reinforced Concrete Buildings},
    institution = {University of Kansas Structural Engineering and Materials Laboratory},
    date      = {1987},
    location  = {Lawrence, KS},
    pages     = {73},
    }

@book{seae,
    author    = {Departamento de Tecnología Industrial},
    title     = {Código Técnico de la Edificación. Documento Básico SE-AE Seguridad Estructural: Acciones en la Edificación},
    location  = {Madrid},
    date      = {2007},
    pages     = {9},
    }

@book{bael,
    title    = {Règles de techniques de conception et de calcul des ouvrages et construction en béton armé suivant la méthode des états limites},
    author   = {Ministère de l'Equipement des Transports et du Logement},
    location = {Paris},
    date     = {1999},
    pages    = {86-87},
    }

@book{is,
    title    = {Plain and Reinforced Concrete - Code of Practice IS 456-2000},
    edition  = {Fourth},
    author   = {Bureau of Indian Standards},
    location = {Nueva Delhi},
    date     = {2000},
    pages    = {86-87},
    }

@report{pca-joints,
    title    = {Buildings Movements and Joints},
    author   = {Portland Cement Association},
    location = {Skokie, Illinois},
    date     = {1983},
    pages    = {36},
    }

@report{nationalacademy-joints,
    title    = {Expansion Joints in Buildings},
    author   = {Standing Commitee on Structural Engineering of the Federal Construction Council},
    number   = {Technical Report No. 65},
    institution    = {National Academy of Sciences},
    location       = {Washington},
    date           = {1974},
    pagetotal      = {43},
    }

@book{vallecilla,
    author    = {C. Ramiro Vallecilla},
    title     = {Fuerzas Sísmicas Principios y Aplicaciones NSR-98},
    publisher = {Editorial Bauen},
    location  = {Bogotá},
    date      = {2003},
    pages     = {192-201},
    }

@online{senhami,
    author          = {Servicion Nacional de Meteorología e Hidrología},
    organization    = {Ministerio del Ambiente},
    title           = {Datos Históricos},
    url             = {http://www.senamhi.gob.pe/main_mapa.php?t=dHi},
    }

This image depicts, what I want,image

2

I really hope someone can come up with a cleaner solution than this, but here we go.

Based on Audrey's answer to How to split the bibliography alphabetically? and an answer of mine to Define bibchecks using a loop heavily making use of Audrey's answer I would suggest the following.

We will use the numeric style and its prefixnumbers option for this solution (the latter requires defernumbers be enabled).

First, we create a bibliography category for each letter of the alphabet, making sure that skipped entries do not cause trouble

\makeatletter
\def\ifskipbib{\iftoggle{blx@skipbib}}
\makeatother

\def\initlist{}
\forcsvlist{\listadd\initlist}{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
\forlistloop{\DeclareBibliographyCategory}{\initlist}
\AtDataInput{\ifskipbib{}{\addtocategory{\thefield{sortinit}}{\thefield{entrykey}}}}

Then, in the document, we loop over all the categories and print them: each category gets its own bibliography prefixed via prefixnumbers by the relevant letter (of course, we would also like a heading)

\printbibheading
\foreach \letter in {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}{%
  \begingroup\edef\myprintbib{\endgroup\printbibliography[category=\letter,prefixnumbers=\letter,heading=none]}\myprintbib
}

The slightly weird \edef definition is due to expansion (I could not get it right otherwise, so better ideas are very welcome).

MWE

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish, es-noshorthands]{babel}
\usepackage{filecontents}
\usepackage{csquotes}
\usepackage{pgffor}
\usepackage[backend=biber,style=numeric,backend=biber,defernumbers]{biblatex}
\usepackage{hyperref}
\begin{filecontents*}{\jobname.bib}
@book{morales,
  author    = {R. Morales},
  title     = {Diseño Estructural Sismorresistente},
  publisher = {Fondo Editorial ICG},
  year      = {2002},
  address   = {Lima},
  pages     = {4-5},
}

@book{macgregor,
  author    = {J. MacGregor and J. Wight},
  title     = {Reinforced Concrete Mechanics and Design},
  publisher = {Prentice Hall},
  date      = {2011},
  location  = {Upper Saddle River, New Jersey},
  pages     = {71-71},
}

@report{pfeiffer,
  author    = {Michael J. Pfeiffer and David Darwin},
  title     = {Joint Design for Reinforced Concrete Buildings},
  institution = {University of Kansas Structural Engineering and Materials Laboratory},
  date      = {1987},
  location  = {Lawrence, KS},
  pages     = {73},
}

@book{seae,
  author    = {{Departamento de Tecnología Industrial}},
  title     = {Código Técnico de la Edificación. Documento Básico SE-AE Seguridad Estructural: Acciones en la Edificación},
  location  = {Madrid},
  date      = {2007},
  pages     = {9},
}

@book{bael,
  title    = {Règles de techniques de conception et de calcul des ouvrages et construction en béton armé suivant la méthode des états limites},
  author   = {{Ministère de l'Equipement des Transports et du Logement}},
  location = {Paris},
  date     = {1999},
  pages    = {86-87},
}

@book{is,
  title    = {Plain and Reinforced Concrete - Code of Practice IS 456-2000},
  edition  = {Fourth},
  author   = {Bureau of Indian Standards},
  location = {Nueva Delhi},
  date     = {2000},
  pages    = {86-87},
}

@report{pca-joints,
    title    = {Buildings Movements and Joints},
    author   = {{Portland Cement Association}},
    location = {Skokie, Illinois},
    date     = {1983},
    pages    = {36},
}

@report{nationalacademy-joints,
  title         = {Expansion Joints in Buildings},
  author        = {{Standing Commitee on Structural Engineering of the Federal Construction Council}},
  number        = {Technical Report No. 65},
  institution   = {National Academy of Sciences},
  location      = {Washington},
  date          = {1974},
  pagetotal     = {43},
}

@book{vallecilla,
  author    = {C. Ramiro Vallecilla},
  title     = {Fuerzas Sísmicas Principios y Aplicaciones NSR-98},
  publisher = {Editorial Bauen},
  location  = {Bogotá},
  date      = {2003},
  pages     = {192-201},
}

@online{senhami,
  author          = {{Servicion Nacional de Meteorología e Hidrología}},
  organization    = {Ministerio del Ambiente},
  title           = {Datos Históricos},
  url             = {http://www.senamhi.gob.pe/main_mapa.php?t=dHi},
}
\end{filecontents*}

\addbibresource{\jobname.bib}

\makeatletter
\def\ifskipbib{\iftoggle{blx@skipbib}}
\makeatother

\def\initlist{}
\forcsvlist{\listadd\initlist}{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
\forlistloop{\DeclareBibliographyCategory}{\initlist}
\AtDataInput{\ifskipbib{}{\addtocategory{\thefield{sortinit}}{\thefield{entrykey}}}}

\begin{document}
These are my references, \cite{bael}, \cite{is}, \cite{macgregor}, \cite{morales}, \cite{nationalacademy-joints}, \cite{pfeiffer}.
\printbibheading
\foreach \letter in {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}{%
  \begingroup\edef\myprintbib{\endgroup\printbibliography[category=\letter,prefixnumbers=\letter,heading=none]}\myprintbib
}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.