Skip to content

Commit

Permalink
Add option abbreviate.journal
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Mar 7, 2020
1 parent 5ef7046 commit 9dde0a4
Show file tree
Hide file tree
Showing 15 changed files with 587 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 新增选项 `only.start.page`
- 增加选项 `title.in.journal`
- 增加选项 `space.before.pages`
- 增加选项 `abbreviate.journal`

## [v2.0] - 2020-03-04
### Changed
Expand Down
37 changes: 37 additions & 0 deletions gbt7714-author-year.bst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ INTEGERS {
show.medium.type
slash.for.extraction
in.booktitle
abbreviate.journal
italic.jounal
bold.journal.volume
show.missing.address.publisher
Expand Down Expand Up @@ -58,6 +59,7 @@ FUNCTION {load.config}
#1 'show.medium.type :=
#1 'slash.for.extraction :=
#0 'in.booktitle :=
#0 'abbreviate.journal :=
#0 'italic.jounal :=
#0 'bold.journal.volume :=
#1 'show.missing.address.publisher :=
Expand Down Expand Up @@ -869,8 +871,43 @@ FUNCTION {format.series.vol.num.booktitle}
if$
}

FUNCTION {remove.period}
{ 't :=
"" 's :=
{ t empty$ not }
{ t #1 #1 substring$ 'tmp.str :=
tmp.str "." = not
{ s tmp.str * 's := }
'skip$
if$
t #2 global.max$ substring$ 't :=
}
while$
s
}

FUNCTION {abbreviate}
{ remove.period
't :=
t "l" change.case$ 's :=
""
s "physical review letters" =
{ "Phys Rev Lett" }
'skip$
if$
's :=
s empty$
{ t }
{ pop$ s }
if$
}

FUNCTION {format.journal}
{ journal
abbreviate.journal
'abbreviate
'skip$
if$
italic.jounal entry.lang lang.en = and
'italicize
'skip$
Expand Down
37 changes: 37 additions & 0 deletions gbt7714-numerical.bst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ INTEGERS {
show.medium.type
slash.for.extraction
in.booktitle
abbreviate.journal
italic.jounal
bold.journal.volume
show.missing.address.publisher
Expand All @@ -52,6 +53,7 @@ FUNCTION {load.config}
#1 'show.medium.type :=
#1 'slash.for.extraction :=
#0 'in.booktitle :=
#0 'abbreviate.journal :=
#0 'italic.jounal :=
#0 'bold.journal.volume :=
#1 'show.missing.address.publisher :=
Expand Down Expand Up @@ -858,8 +860,43 @@ FUNCTION {format.series.vol.num.booktitle}
if$
}

FUNCTION {remove.period}
{ 't :=
"" 's :=
{ t empty$ not }
{ t #1 #1 substring$ 'tmp.str :=
tmp.str "." = not
{ s tmp.str * 's := }
'skip$
if$
t #2 global.max$ substring$ 't :=
}
while$
s
}

FUNCTION {abbreviate}
{ remove.period
't :=
t "l" change.case$ 's :=
""
s "physical review letters" =
{ "Phys Rev Lett" }
'skip$
if$
's :=
s empty$
{ t }
{ pop$ s }
if$
}

FUNCTION {format.journal}
{ journal
abbreviate.journal
'abbreviate
'skip$
if$
italic.jounal entry.lang lang.en = and
'italicize
'skip$
Expand Down
88 changes: 88 additions & 0 deletions gbt7714.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ INTEGERS {
show.medium.type
slash.for.extraction
in.booktitle
abbreviate.journal
italic.jounal
bold.journal.volume
show.missing.address.publisher
Expand Down Expand Up @@ -894,6 +895,16 @@ FUNCTION {load.config}
#0 'in.booktitle :=
% \end{macrocode}
%
% 期刊名使用缩写:
% \begin{macrocode}
%<*!abbreviate-journal&!npr>
#0 'abbreviate.journal :=
%</!abbreviate-journal&!npr>
%<*abbreviate-journal|npr>
#1 'abbreviate.journal :=
%</abbreviate-journal|npr>
% \end{macrocode}
%
% 期刊名使用斜体:
% \begin{macrocode}
#0 'italic.jounal :=
Expand Down Expand Up @@ -2192,8 +2203,85 @@ FUNCTION {format.series.vol.num.booktitle}
if$
}
FUNCTION {remove.period}
{ 't :=
"" 's :=
{ t empty$ not }
{ t #1 #1 substring$ 'tmp.str :=
tmp.str "." = not
{ s tmp.str * 's := }
'skip$
if$
t #2 global.max$ substring$ 't :=
}
while$
s
}
FUNCTION {abbreviate}
{ remove.period
't :=
t "l" change.case$ 's :=
""
s "physical review letters" =
{ "Phys Rev Lett" }
'skip$
if$
%<*npr>
s "china physics c" =
{ "Chin Phys C" }
'skip$
if$
s "chinese physics letters" =
{ "Chin Phys Lett" }
'skip$
if$
s "nuclear instruments and methods in physics research section a" =
{ "Nucl Instr and Meth A" }
'skip$
if$
s "nuclear instruments and methods in physics research section a: accelerators, spectrometers, detectors and associated equipment" =
{ "Nucl Instr and Meth A" }
'skip$
if$
s "nuclear instruments and methods in physics research section b" =
{ "Nucl Instr and Meth B" }
'skip$
if$
s "nuclear instruments and methods in physics research section b: beam interactions with materials and atoms" =
{ "Nucl Instr and Meth B" }
'skip$
if$
s "physical review c" =
{ "Phys Rev C" }
'skip$
if$
s "physical review d" =
{ "Phys Rev D" }
'skip$
if$
s "physical review e" =
{ "Phys Rev E" }
'skip$
if$
s "physics letters b" =
{ "Phys Lett B" }
'skip$
if$
%</npr>
's :=
s empty$
{ t }
{ pop$ s }
if$
}
FUNCTION {format.journal}
{ journal
abbreviate.journal
'abbreviate
'skip$
if$
italic.jounal entry.lang lang.en = and
'italicize
'skip$
Expand Down
2 changes: 1 addition & 1 deletion test/testbst/npr.bbl
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ Philips data handbook for electron tubes t9\allowbreak[M].

\bibitem[Sackett et~al.(1993)Sackett, Ieki, A, et~al.]{sackett1993}
SACKETT~D, IEKI~K, A~G, et~al.
\newblock Physical Review C, 1993, 48\penalty0 (1): 118.
\newblock Phys Rev C, 1993, 48\penalty0 (1): 118.

\bibitem[Sackett et~al.(1997)Sackett, Ieki, A, et~al.]{zecher1997}
SACKETT~D, IEKI~K, A~G, et~al.
Expand Down
50 changes: 50 additions & 0 deletions tools/abbr-journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
abbrs = {
'China Physics C': 'Chin Phys C',
'Chinese Physics Letters': 'Chin Phys Lett',
'Nuclear Instruments and Methods in Physics Research Section A': 'Nucl Instr and Meth A',
'Nuclear Instruments and Methods in Physics Research Section A: Accelerators, Spectrometers, Detectors and Associated Equipment': 'Nucl Instr and Meth A',
'Nuclear Instruments and Methods in Physics Research Section B': 'Nucl Instr and Meth B',
'Nuclear Instruments and Methods in Physics Research Section B: Beam Interactions with Materials and Atoms': 'Nucl Instr and Meth B',
'Physical Review C': 'Phys Rev C',
'Physical Review D': 'Phys Rev D',
'Physical Review E': 'Phys Rev E',
'Physical Review Letters': 'Phys Rev Lett',
'Physics Letters B': 'Phys Lett B',
}

lines = []

lines.append('''\
FUNCTION {abbreviate.journal}
{ 't :=
t "l" change.case$ 's :=
''')

# for k, v in abbrs.items():
# lines.append(f' s "{k.lower()}" =\n {{ "{v}" }} {{\n')
# lines.append(f' t\n')
# for _ in range(len(abbrs)):
# lines.append(f' }} if$\n')

for k, v in abbrs.items():
k = k.replace('.', '').lower()
lines.append(f' s "{k}" =\n')
lines.append(f' {{ "{v}" }}\n')
lines.append(f' \'skip$\n')
lines.append(f' if$\n')

lines.append('''\
\'s :=
s empty$
{ t }
{ s }
if$
}
''')


for line in lines:
print(line, end='')

with open('abbr.bst', 'w') as f:
f.writelines(lines)
37 changes: 37 additions & 0 deletions variants/2005/gbt7714-2005-author-year.bst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ INTEGERS {
show.medium.type
slash.for.extraction
in.booktitle
abbreviate.journal
italic.jounal
bold.journal.volume
show.missing.address.publisher
Expand Down Expand Up @@ -58,6 +59,7 @@ FUNCTION {load.config}
#1 'show.medium.type :=
#1 'slash.for.extraction :=
#0 'in.booktitle :=
#0 'abbreviate.journal :=
#0 'italic.jounal :=
#0 'bold.journal.volume :=
#1 'show.missing.address.publisher :=
Expand Down Expand Up @@ -869,8 +871,43 @@ FUNCTION {format.series.vol.num.booktitle}
if$
}

FUNCTION {remove.period}
{ 't :=
"" 's :=
{ t empty$ not }
{ t #1 #1 substring$ 'tmp.str :=
tmp.str "." = not
{ s tmp.str * 's := }
'skip$
if$
t #2 global.max$ substring$ 't :=
}
while$
s
}

FUNCTION {abbreviate}
{ remove.period
't :=
t "l" change.case$ 's :=
""
s "physical review letters" =
{ "Phys Rev Lett" }
'skip$
if$
's :=
s empty$
{ t }
{ pop$ s }
if$
}

FUNCTION {format.journal}
{ journal
abbreviate.journal
'abbreviate
'skip$
if$
italic.jounal entry.lang lang.en = and
'italicize
'skip$
Expand Down
Loading

0 comments on commit 9dde0a4

Please sign in to comment.