Skip to content

Instantly share code, notes, and snippets.

@k16shikano
Last active January 1, 2021 01:17
Show Gist options
  • Save k16shikano/3f441715ae5bcfa8d9d58af9c900fd0a to your computer and use it in GitHub Desktop.
Save k16shikano/3f441715ae5bcfa8d9d58af9c900fd0a to your computer and use it in GitHub Desktop.
スペース区切りかもしれない文字列のアクロニムを3文字ぶん切り出す(u)pbibtex関数(ただし漢字を含む文字列の場合は先頭の2文字を切り出す)
STRINGS { s t str org car result }
INTEGERS { len }
FUNCTION {chop.word}
{ 's :=
'len :=
s #1 len substring$ =
{ s len #1 + global.max$ substring$ }
{ s }
if$
}
FUNCTION {chop.article}
{ 't :=
"A" " " * #2
"An" " " * #3
"The" " " * #4 t chop.word
chop.word
chop.word
}
FUNCTION {acronym.word}
{ duplicate$ 'org := chop.article 'str :=
org is.kanji.str$
{ org #5 text.prefix$ purify$ 'result := }
{ str #1 #1 substring$ 'result :=
{ str empty$ #0 = }
{ str #1 #1 substring$ 'car :=
car " " =
{ str #2 global.max$ substring$ chop.article 'str :=
result str #1 #1 substring$ * 'result :=
} { skip$ } if$
str #2 global.max$ substring$ 'str :=
}
while$
result text.length$ #3 <
{ org chop.article #1 #3 substring$ 'result := }
{ result #1 #3 substring$ 'result := }
if$
}
if$
result
}
FUNCTION {test}
{ "abc dfg df fg" acronym.word top$ }
FUNCTION {jatest}
{ "日本語が 含まれる場合" acronym.word top$ }
ENTRY{}{}{}
READ
EXECUTE{test} % add
EXECUTE{jatest} % 日本
\documentclass[uplatex,dvipdfmx]{jbook}
\begin{document}
\bibliographystyle{acronym}
\bibliography{anything.bib}
\end{document}
$ upbibtex bibtest
This is upBibTeX, Version 0.99d-j0.33-u1.26 (utf8.uptex) (TeX Live 2020)
The top-level auxiliary file: bibtest.aux
The style file: acronym.bst
I found no \citation commands---while reading file bibtest.aux
Warning--I didn't find any fields--line 51 of file acronym.bst
Database file #1: anything.bib
add
日本
(There were 1 error messages)
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment