summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/biblatex-contrib/biblatex-shortfields/biblatex-shortfields.sty
blob: ee8f6e875280dce24dd2616ebec77d2405c9d734 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
%% Copyright 2017-… Maïeul Rouquette
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Maïeul Rouquette
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{biblatex-shortfields}[2017/11/19 v1.0.1 Print unique list of short fields]
\providecommand{\biblatex@claves}{}%
% 1. Use short version of fields instead of long version 
\renewbibmacro*{series+number}{%
  \iffieldundef{shortseries}{\printfield{series}}{\printfield{shortseries}}%
  \setunit*{\addspace}%
  \printfield{number}%
  \newunit}

\renewbibmacro*{journal}{%
  \iffieldundef{shortjournal}{%
  \iffieldundef{journaltitle}%
    {}%
    {\printtext[journaltitle]{%
       \printfield[titlecase]{journaltitle}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{journalsubtitle}}}%
  }{%
    \printtext[journaltitle]{\printfield[titlecase]{shortjournal}}%
  }%
}%
  

% 2. Custom sorting scheme
  
\ifdef{\DeclareSortingTemplate}%
  {}%
  {\let\DeclareSortingTemplate\DeclareSortingScheme}%

\DeclareSortingTemplate{shortfields}{
  \sort{
    \field{claves_definition}
    \field{shortjournal}
    \field{shortseries}
  }
  \sort{
    \field{series}
    \field{journaltitle}
  }
}

%3. Bibcheck

\defbibcheck{shortfields}{%
  %First, the entrytype NOT corresponding to claves
  \iffieldundef{claves_definition}%
    {% If not the corresponding to a claves
    \ifboolexpr{%
      (test{\iffieldundef{shortseries}} or test{\iffieldundef{series}})%
       and%
      (test {\iffieldundef{shortjournal}} or test {\iffieldundef{journaltitle}})%
      }{%
      \skipentry%
    }{%
      %For series
      \ifboolexpr{%
        test {\iffieldundef{series}}%
        and% 
        test {\iffieldundef{shortseries}}%
        }{}%
          {%
            \ifcsdef{\strfield{shortseries}=\strfield{series}}{%
            \skipentry%
          }{%
            \savefieldcs{series}{\strfield{shortseries}=\strfield{series}}%
          }%
        }%
      % For journal
      \ifboolexpr{%
        test {\iffieldundef{journaltitle}}%
        and%
        test {\iffieldundef{shortjournal}}%
        }{}%
          {%
          \ifcsdef{\strfield{shortjournal}=\strfield{journaltitle}}{%
          \skipentry%
          }{%
          \savefieldcs{journaltitle}{\strfield{shortjournal}=\strfield{journaltitle}}%
        }%
      }%
    }%
   }%
   {}%
}%


\newlength{\shortfieldswidth}
\setlength{\shortfieldswidth}{4em}
\defbibenvironment{shortfields}
  {%
  \let\old@blx@driver\blx@driver%
  \ifdef{\clavesadddashinset}{%
    \clavesadddashinset%Add the dash inside set (modify default style)
    \renewcommand{\entrysetpunct}{\endgraf}%Break between set of an enty
  }{}%
  \renewcommand{\blx@driver}[1]{\blx@bbx@shortfields}%
  \list{%
    \iffieldundef{claves_definition}%
      {%
      \printfield{shortseries}%
      \printfield[journaltitle]{shortjournal}%
      }%
      {\printfield[claves_definition]{entrykey}}%
    }%
    {%
     \labelwidth\shortfieldswidth
     \labelsep\biblabelsep
     \leftmargin\labelwidth
     \advance\leftmargin\labelsep
     \itemsep\bibitemsep
     \parsep\bibparsep
     \def\makelabel##1{##1\hss}}}
  {\endlist}
  {\item}

\DeclareBibliographyDriver{shortfields}{%
  \iffieldundef{claves_definition}%
    {%
    \printfield{series}%
    \printfield{journaltitle}%
    }%
    {\let\blx@driver\old@blx@driver\blx@driver{\thefield{entrytype}}}%
}

% The use level command
\newcommand{\printbibshortfields}[1][title=\biblistname]{%
  \begin{refcontext}[sorting=shortfields]
  \printbibliography[check=shortfields,env=shortfields,#1]%
  \end{refcontext}
}


\endinput