diff options
author | Karl Berry <karl@freefriends.org> | 2022-04-05 22:38:21 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-04-05 22:38:21 +0000 |
commit | 7586cd554d81dbc4cccd6973bb553024afe77ff6 (patch) | |
tree | 3f7e864e01b3598a477a144948deea09b3b09a27 /Master/texmf-dist/doc/bibtex | |
parent | c9a6d1abe2565fa523fb85615b9a4ec5467bf09b (diff) |
ieejtran (29mar22)
git-svn-id: svn://tug.org/texlive/trunk@62957 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/bibtex')
-rw-r--r-- | Master/texmf-dist/doc/bibtex/ieejtran/README | 22 | ||||
-rw-r--r-- | Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.pdf | bin | 0 -> 29797 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.tex | 86 | ||||
-rw-r--r-- | Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.pdf | bin | 0 -> 114361 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.tex | 378 | ||||
-rw-r--r-- | Master/texmf-dist/doc/bibtex/ieejtran/mixej.py | 486 |
6 files changed, 972 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/bibtex/ieejtran/README b/Master/texmf-dist/doc/bibtex/ieejtran/README new file mode 100644 index 00000000000..643f36b7be0 --- /dev/null +++ b/Master/texmf-dist/doc/bibtex/ieejtran/README @@ -0,0 +1,22 @@ +March 26, 2021 + + +IEEJtran is an UNOFFICIAL BibTeX style for authors of the Institute of +Electrical Engineers of Japan (IEEJ) transactions journals and conferences. +IEEJtran is an expansion package of Michael Shell's IEEEtran package. +The latest version of the IEEJtran package can be found at CTAN: + +http://www.ctan.org/pkg/ieejtran + +Problems, requests, tips, beta releases, and other support, can be seen +in IEEJtran's GitHub page: + +https://github.com/ehki/jIEEEtran + +NOTE: The author also developing jIEEEtran.bst in the same repository. + +IEEJtran may be distributed and/or modified under the terms of MIT license. + +Best wishes for all your publication endeavors, + +Haruki Ejiri diff --git a/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.pdf b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.pdf Binary files differnew file mode 100644 index 00000000000..70f66605ad7 --- /dev/null +++ b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.pdf diff --git a/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.tex b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.tex new file mode 100644 index 00000000000..2fa8a6af27e --- /dev/null +++ b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran-en.tex @@ -0,0 +1,86 @@ +\documentclass[11pt, a4paper, dvipdfmx]{article} + +\usepackage{bxtexlogo} + +\begin{filecontents}[overwrite]{library.bib} +@misc{IEEEtran, + author = {Michael Shell}, + url = {https://www.ctan.org/tex-archive/macros/latex/contrib/IEEEtran/bibtex}, + title = {{IEEEtran}}, + month = {August}, + year = {2015} +} +@misc{jIEEEtran, + author = {ehki}, + url = {https://github.com/ehki/jIEEEtran}, + title = {{jIEEEtran}}, + month = {March}, + year = {2020} +} +@misc{jeconbst, + author = {ShiroTakeda}, + url = {http://shirotakeda.org/ja/tex-ja/jecon-ja.html}, + title = {{jecon.bst}}, + month = {August}, + year = {2019} +} +\end{filecontents} + + +\title{\texttt{IEEJtran.bst}:\\Unofficial IEEJ \BibTeX\ style\\(ver. 0.18)} +\author{Haruki EJIRI} + +\begin{document} + +\maketitle + +\begin{abstract} +The IEEJtran \BibTeX\ style is an unofficial citation format for Institute of Electrical Engineers of Japan transactions. +It is a customization of Michael Shell's IEEEtran.bst. +A Python script named mixej.py enables one content with both English and Japanese format to be handled properly. +\end{abstract} + + +\section{Introduction} + +IEEJtran.bst is an unofficial \BibTeX-style (.bst) file in IEEJ format developed for Japanese users engaging in electrical engineering. +YoshiRi implemented natural Japanese notation based on Michael Shell's IEEEtran.bst[?]. +And now the author develops it in GitHub repository [?] after taking it over. +Please note IEEJtran.bst is unofficial. +The author does not guarantee that it will work in all environments. +We cannot be held responsible for any problems that may occur. +We recommend platex/pbibtex or uplatex/upbibtex as \TeX\ engines. + + +\section{Configuration} + +If IEEJtran.bst has been installed by \TeX\ Live package manager, etc., and placed under PATH, write \texttt{\string\bibliographystyle\string{IEEJtran\string}} in the preamble to complete the setup. +In the case that IEEJtran.bst is individually downloaded and placed in the same directory as the main \TeX\ file such a reason for customization, state \texttt{\string\bibliographystyle\string{IEEJtran\string}} in the preamble in the same way to complete the setting. +In the .bib file containing bibliographic information, Japanese authors' names should be written as: +\begin{center} +\texttt{author = \string{\string{Yamada Taro\string} and \string{Sato Jiro\string}\string}}, +\end{center} +or +\begin{center} +\texttt{author = \string{Yamada, Taro and Sato, Jiro\string}}. +\end{center} + + +\section{Combine English and Japanese entries} + +Japanese users are sometimes required to write both English and Japanese citation formats as one bibliography entry. +A python script named \texttt{mixej.py} included in the \texttt{ieejtran} package enables combining English and Japanese entries. +To combine two entries of enkey and jpkey, users have to cite as \texttt{\string\cite\string{enkye/ej/jpkey\string}}, where enkey and jpkey are English and Japanese citation keys, respectively. +Then compile by the following seven steps: +\begin{center} + \texttt{uplatex → python mixej.py → upbibtex → python mixej.py\\→ uplatex → uplatex → dvipdfmx} +\end{center} +instead of the typical five steps: +\begin{center} + \texttt{uplatex → upbibtex → uplatex → uplatex → dvipdfmx}. +\end{center} +Note that the uplatex command is Unicode and Japanese compatible latex command. + +The Japanese version of this document, \texttt{ieejtran.pdf}, shows examples for English and Japanese combined citations. + +\end{document} diff --git a/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.pdf b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.pdf Binary files differnew file mode 100644 index 00000000000..0d0184d6d10 --- /dev/null +++ b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.pdf diff --git a/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.tex b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.tex new file mode 100644 index 00000000000..042595eb11d --- /dev/null +++ b/Master/texmf-dist/doc/bibtex/ieejtran/ieejtran.tex @@ -0,0 +1,378 @@ +\documentclass[11pt, a4paper, dvipdfmx, uplatex]{jsarticle} +\bibliographystyle{IEEJtran} + +\usepackage{listings, jlisting} +\lstdefinestyle{onecol}{ + basicstyle={\scriptsize\ttfamily}, + identifierstyle={\footnotesize}, + commentstyle={\footnotesizeitshape}, + keywordstyle={\footnotesize\bfseries}, + ndkeywordstyle={\footnotesize}, + stringstyle={\footnotesize\ttfamily}, + breaklines=true, + columns=[l]{fullflexible} +} + +\begin{filecontents}[overwrite]{library.bib} +@misc{IEEEtran, + author = {Michael Shell}, + url = {https://www.ctan.org/tex-archive/macros/latex/contrib/IEEEtran/bibtex}, + title = {{IEEEtran}}, + month = {August}, + year = {2015} +} +@misc{jIEEEtran, + author = {ehki}, + url = {https://github.com/ehki/jIEEEtran}, + title = {{jIEEEtran}}, + month = {March}, + year = {2020} +} +@misc{jeconbst, + author = {ShiroTakeda}, + url = {http://shirotakeda.org/ja/tex-ja/jecon-ja.html}, + title = {{jecon.bst}}, + month = {August}, + year = {2019} +} +@article{jpArticle1, + author = {山田 一郎 and 山田 次郎 and 山田 三郎 and 山田 四郎}, + year = {2019}, + journal = {日本語学会}, + title = {文献1}, + number = {10}, + pages = {20--30}, + volume = {15}, + month = {3} +} +@article{jpArticle2, + author = {{山田 五郎} and {山田 六郎}}, + year = {2019}, + journal = {日本語学会}, + title = {文献2}, + number = {10}, + pages = {21}, + volume = {15}, + month = {12} +} +@article{jpArticle3, + author = {{山田 八郎} and {山田 六郎}}, + year = {2010}, + journal = {日本語学会}, + title = {手法1と手法2の比較検討}, + number = {1}, + pages = {15}, + volume = {5} +} +@article{enArticle1, + author = {Ichiro Yamada and Jiro Yamada and Saburo Yamada and Shiro Yamada}, + year = {2019}, + journal = {Japanese Journal}, + title = {Title1}, + number = {10}, + pages = {20--30}, + volume = {15}, + month = {march}, + language = {Japanese} +} +@article{enArticle2, + author = {Goro Yamada and Rokuro Yamada}, + year = {2019}, + journal = {Japanese Journal}, + title = {Title2}, + volume = {15}, + number = {10}, + pages = {21}, + month = {dec.}, + language = {Japanese} +} +@article{enArticle3, + author = {Hachiro Yamada and Rokuro Yamada}, + year = {2010}, + journal = {Japanese Journal}, + title = {Comparison Between Method 1 and Method 2}, + number = {1}, + pages = {15}, + volume = {5} +} +@inproceedings{jpInproceedings1, + author = {山田, 一郎 and 山田, 次郎}, + title = {文献タイトル}, + booktitle = {令和2年日本語大会}, + address = {大阪}, + year = {2010}, + month = {3}, + number = {10}, + pages = {20--30} +} +@inproceedings{jpInproceedings2, + author = {山田, 三郎 and 佐藤, 四郎}, + title = {タイトル}, + booktitle = {第30回部門大会}, + address = {東京}, + year = {2005}, + month = {2}, + number = {2}, + pages = {15--19} +} +@inproceedings{enInproceedings1, + author = {Hayashi, Shinji and Ogura, Yasuhiro}, + title = {Sample Conference Article Title}, + booktitle = {Proc. 5th Internatinoal Sample Conference (ISC)}, + address = {Tokyo, Japan}, + month = {jan}, + year = {1997}, + pages = {290-294}, + number = {2} +} +@inproceedings{enInproceedings2, + author = {Yamada, Sabuso and Sato, Shiro}, + title = {Title}, + booktitle = {Proc. 30th Society Conference}, + address = {Tokyo}, + year = {2005}, + month = {2}, + number = {2}, + pages = {15--19}, + language = {Japanese} +} +@incollection{jpIncollection1, + author = {{佐藤 二郎} and {林 三郎}}, + year = {2012}, + publisher = {日本語出版}, + address = {東京}, + title = {日本語本2の中の抜粋}, + booktitle = {日本語本2}, + edition = {2}, + pages = {100--200} +} +@incollection{jpIncollection2, + author = {山田, 一郎}, + year = {1900}, + publisher = {出版会社}, + address = {東京}, + title = {タイトル}, + booktitle = {日本語本3}, + chapter = {3}, + edition = {1}, + pages = {100--150}, +} +@incollection{enIncollection1, + address = {Tokyo, Japan}, + publisher = {JP Press}, + author = {Sato, Jiro and Hayashi, Saburo}, + booktitle = {Jpbook2}, + title = {Part of Jpbook2}, + pages = {100--200}, + edition = {2}, + year = {2012}, +} +@book{jpBook1, + author = {佐藤, 一郎}, + year = {2010}, + publisher = {日本語出版}, + address = {東京}, + title = {日本語本}, + edition = {1}, + pages = {100--200} +} +@book{jpBook2, + author = {佐藤, 二郎 and 佐藤, 三郎}, + year = {2012}, + publisher = {日本語出版}, + address = {東京}, + title = {日本語本2}, + edition = {2}, + pages = {100--200} +} +@book{jpBook3, + author = {学会委員会}, + year = {2020}, + publisher = {学会出版}, + title = {学会本}, + edition = {1} +} +@book{enBook1, + address = {City, Country}, + publisher = {Publisher}, + author = {Sato, Jiro and Hayashi, Saburo}, + year = {2000}, + title = {Title, not booktitle}, + edition = {3}, + pages = {1-10}, +} +@book{enjBook1, + author = {Ichiro Sato}, + year = {2010}, + publisher = {Japanese Publisher}, + address = {Tokyo}, + title = {Japanese Book title}, + edition = {1}, + pages = {100--200}, + language = {japaneese} +} +@book{jpjBook1, + author = {佐藤 一郎}, + year = {2010}, + publisher = {日本語出版}, + address = {東京}, + title = {日本語本}, + edition = {1}, + pages = {100--200} +} +\end{filecontents} + + +\title{\texttt{IEEJtran.bst}:\\電気学会非公式\BibTeX スタイル\\(ver. 0.18)} +\author{江尻 開} + +\begin{document} + +\maketitle + +\begin{abstract} +IEEJtranは電気学会形式の非公式\BibTeX スタイルです。 +Michael Shell氏のIEEEtran.bstを基に開発されています。 +一つのエントリに英語と日本語を併記可能とするPythonスクリプトmixej.pyも提供します。 +\end{abstract} + + +\section{はじめに} + +\texttt{IEEJtran.bst}は電気系の論文を執筆する日本人ユーザ向けに開発された電気学会形式の非公式\BibTeX スタイル(\texttt{.bst})ファイルです。 +電気学会論文誌の下書きや卒業論文,修士論文など,\LaTeX を使用した文献管理の一助になることを目的としています。 +Michael Shell氏による\texttt{IEEEtran.bst}\cite{IEEEtran}をもとにYoshiRi氏が日本語の自然な表記を実装し,現在は著者がリポジトリを譲渡していただきGitHub上\cite{jIEEEtran}で継続して開発しています。 +同レポジトリではIEEEの引用スタイルを保ったまま日本語の取り扱いを自然にした\BibTeX スタイルである\texttt{jIEEEtran.bst}も取り扱っています。 +オプションの追記方法や日本語の判別方法については,武田氏らによる\texttt{jecon.bst}\cite{jeconbst}を参考にしています。 +\TeX Live 2019以降の使用を想定しています。 +\texttt{w32tex}や古い\TeX Liveでの動作は確認していません。 +\TeX エンジンとしてplatex/pbibtexもしくはuplatex/upbibtexを推奨し,本マニュアルはuplatexでコンパイルしています。 +\TeX エンジンが出力する中間ファイルの改変にPythonを使用します。 +Pythonは\texttt{3.7}以降での動作を確認しています。 + + +\section{使用方法} + +\texttt{IEEJtran.bst}が\TeX Liveのパッケージマネージャ等でインストールされ,PATHの通った場所に配置されている場合,プリアンブルに\texttt{\string\bibliographystyle\string{IEEJtran\string}}と記載すれば設定は完了です。 +後述のカスタマイズ等の目的で\texttt{IEEJtran.bst}を個別にダウンロードして配置する場合,メインの\TeX ファイルと同じディレクトリに格納し,同様にプリアンブルに\texttt{\string\bibliographystyle\string{IEEJtran\string}}と記載すれば設定は完了です。 + +文献情報が記載される\texttt{.bib}ファイル上では,日本人著者は +\begin{center} + \texttt{author = \string{\string{\textgt{姓姓 名名}\string} and \string{\textgt{姓姓 名名}\string}\string}} +\end{center} +と,\texttt{\string{\string}}で挟むか, +\begin{center} + \texttt{author = \string{姓姓, 名名 and 姓姓, 名名\string}} +\end{center} +と,\texttt{\string{\string}}で挟まず半角カンマを挿入して記入してください。 + + +\section{カスタマイズ} +\texttt{IEEJtran}はテキストファイルである\texttt{IEEJtran.bst}を直接変更することでカスタマイズが可能です。 +例えば、著者とタイトルの間に挿入される文字を「かぎ括弧」から『二重かぎ括弧』に変更する場合、\texttt{IEEJtran.bst}の +\begin{center} + \texttt{FUNCTION \string{bbl.ieej.jp.title.pre\string} \string{ \string"「\string" \string}}\par + \texttt{FUNCTION \string{bbl.ieej.jp.title.aft\string} \string{ \string"」\string" \string}} +\end{center} +を +\begin{center} + \texttt{FUNCTION \string{bbl.ieej.jp.title.pre\string} \string{ \string"『\string" \string}}\par + \texttt{FUNCTION \string{bbl.ieej.jp.title.aft\string} \string{ \string"』\string" \string}} +\end{center} +に変更します。 +他の設定項目は\texttt{IEEJtran.bst}を直接ご確認ください。 + + +\section{英語と日本語の併記方法} + +電気学会の引用スタイルで求められているように,一つの文献エントリに英語と日本語の情報を併記する場合,\texttt{.tex}ファイルには次のように記載してください。 +\begin{center} + \texttt{\string\cite\string{enArticle1/ej/jpArticle1\string}} +\end{center} +加えて,外部pythonファイルの\texttt{mixej.py}を用いて\texttt{.aux}ファイルと\texttt{.bbl}ファイルを改変する必要があります。 +具体的には,\BibTeX コマンドの実行前に\texttt{enArticle1/ej/jpArticle1\string}を\texttt{enArticle1}と\texttt{jpArticle1}の2つのエントリに分け,\BibTeX コマンドが文献情報を書き出した後に再度結合させる操作を行います。 + + +\subsection{コンパイル手順} + +英語と日本語の併記を行わない場合,通常通りのコンパイル手順で\texttt{.pdf}を生成することができます。 +例えば\texttt{uplatex}で\texttt{.dvi}を生成し,\texttt{.dvi}から\texttt{.pdf}を生成,\BibTeX コマンドには\texttt{upbibtex}を使う場合, +\begin{center} +\texttt{uplatex → upbibtex → uplatex → uplatex → dvipdfmx} +\end{center} +という手順です。 + +英語と日本語の併記を行う場合,通常のコンパイル手順での\texttt{upbibtex}前後に\texttt{python}による\texttt{mixej.py}の処理を一回ずつ挟みます。 +前と同様に,\texttt{uplatex}で\texttt{.dvi}を生成し,\texttt{.dvi}から\texttt{.pdf}を生成,\BibTeX コマンドには\texttt{upbibtex}を使う場合, +\begin{center} +\texttt{uplatex → python mixej.py → upbibtex → python mixej.py\\→ uplatex → uplatex → dvipdfmx} +\end{center} +という手順に変更されます。 + + +\subsection{コンパイラの設定の例} + +Latexmkを使用している場合,MacやLinuxなどのUNIX系列では\texttt{.latexmkrc}に対して次のように設定することで実現可能です。 + +\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}\vspace{-0.5zw} +\begin{lstlisting}[style=onecol] +#!/usr/bin/perl + +$latex = 'uplatex %O -synctex=1 -interaction=nonstopmode -kanji=utf8 -file-line-error %S'; +$bibtex = 'python mixej.py %B; upbibtex %O %B; python mixej.py %B'; +$dvipdf = 'dvipdfmx -V 7 %O -o %D %S'; +$pdf_previewer = "open -ga /Applications/Skim.app"; +\end{lstlisting}\vspace{-1.8zw} +\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}\vspace{0.5zw}\par + +\noindent +Windowsでは,cmd, powershellともに\texttt{bibtex}の設定を次のようにすれば動きます。ただし,\texttt{\&}前後の半角スペースを忘れずに記入してください。 + +\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}\vspace{-0.5zw} +\begin{lstlisting}[style=onecol] +$bibtex = '@cd & python mixej.py %B & upbibtex %B & python mixej.py %B'; +\end{lstlisting}\vspace{-1.8zw} +\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}\vspace{0.5zw}\par + + +最近ではVisual Studio Codeを使用している方が多いと思いますが,MacやLinuxでのVSCodeのLaTeX Workshop Extension用の設定は次のように書けます。Windowsの場合は\texttt{.latexmkrc}の場合と同様に\texttt{bibtex}コマンドを書き換えてください。 + +\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}\vspace{-0.5zw} +\begin{lstlisting}[style=onecol] +"latex-workshop.latex.tools": [ + { + "command": "latexmk", + "name": "latexmk uplatex/upbibtex/mixej", + "args": [ + "-e", "$latex='uplatex %O -synctex=1 -interaction=nonstopmode -kanji=utf8 -file-line-error %S'", + "-e", "$bibtex='python mixej.py %B; upbibtex %O %B; python mixej.py %B'", + "-e", "$dvipdf='dvipdfmx -V 7 %O -o %D %S'", + "-norc", "-pdfdvi", "%DOC%" + ], + } +], +"latex-workshop.latex.recipes": [ + { "name": "latexmk uplatex/upbibtex/mixej", "tools": [ "latexmk uplatex/upbibtex/mixej" ] } +], +\end{lstlisting}\vspace{-1.8zw} +\noindent\makebox[\linewidth]{\rule{\linewidth}{0.4pt}}\vspace{0.5zw}\par + + +\subsection{引用例} + +いくつかの引用例を示します。 +英語Articleの例\cite{enArticle1}。 +日本語Articleの例\cite{jpArticle1}。 +英語と日本語を併記したArticleの例\cite{enArticle2/ej/jpArticle2,enArticle3/ej/jpArticle3}。 +英語Inproceedingsの例\cite{enInproceedings1}。 +日本語Inproceedingsの例\cite{jpInproceedings1}。 +英語と日本語を併記したInproceedingsの例\cite{enInproceedings2/ej/jpInproceedings2}。 +英語Incollectionの例\cite{enIncollection1}。 +日本語Incollectionの例\cite{jpIncollection1,jpIncollection2}。 +英語Bookの例\cite{enBook1}。 +日本語Bookの例\cite{jpBook1,jpBook2,jpBook3}。 +英語と日本語を併記したBookの例\cite{enjBook1/ej/jpjBook1}。 + +\bibliography{library.bib} + +\end{document} diff --git a/Master/texmf-dist/doc/bibtex/ieejtran/mixej.py b/Master/texmf-dist/doc/bibtex/ieejtran/mixej.py new file mode 100644 index 00000000000..f96dbf6f482 --- /dev/null +++ b/Master/texmf-dist/doc/bibtex/ieejtran/mixej.py @@ -0,0 +1,486 @@ +import sys +import platform +import json +import logging + + +SPLIT_KEY = '/ej/' +ITEM_SEP = '\\hspace{0mm}\\\\' + +FILE_VERSION = '0.18' +FILE_DATE = '2022/03/26' +FILE_AUTHOR = 'Haruki Ejiri' +FILE_URL = 'https://github.com/ehki/jIEEEtran/' + +logger = logging.getLogger(__name__) + + +def check_load_file(fn, asjson=False): + """load file if exist else return -1. + + This code load text and json file if exist. + If the file not exist, return -1 + + Parameters + ---------- + fn : str + Path to the file to load + asjson : bool + whether the fn should be loaded using json or normal text file + + Returns + ------- + int + 0 if success + """ + + logger.info('-- Checking file %s, ' % fn) + try: + with open(fn, 'r', encoding='utf-8') as f: + logger.info('exist, load.') + if asjson: + return json.load(f) + else: + return f.read() + except FileNotFoundError: + logger.info('not found.') + return -1 + + +def save_pairs(fn, pairs): + """save pairs to the JSON format file with the extensions of ".ejp". + + This code save the pairs to the file in JSON format. + + Parameters + ---------- + fn : str + Path to the file to write pairs + pairs : list of two strings + for example: [["en1", "jp1"], ["en2", "jp2"], ["en3", "jp3"]] + + Returns + ------- + int + 0 if success + """ + + logger.info('-- Saving found pairs to %s, ' % fn) + with open(fn, 'w', encoding='utf-8') as f: + json.dump(pairs, f) + logger.info('done.') + return 0 + + +def divide_aux(fn, pairs): + """divide comined citation(s) and bibcite(s) in aux file. + + This code divide the combined key(s) in aux file. + For example, the following citation(s) and bibcite(s) in aux file + -- + \\citation{englishTest7/ej/japaneseTest7} + + \\bibcite{englishTest7/ej/japaneseTest7}{16} + -- + will be converted to the following two divided citations and bibitems. + -- + \\citation{englishTest7,japaneseTest7} + + \\bibcite{englishTest7,japaneseTest7}{16} + -- + + Parameters + ---------- + fn : str + Path to the aux file to proceess + pairs : list of two strings + for example: [["en1", "jp1"], ["en2", "jp2"], ["en3", "jp3"]] + + Returns + ------- + int + -1 if the file to process not found, 0 if success + """ + + aux = check_load_file(fn) + if aux == -1: # file not found + return -1 # failed + for k1, k2 in pairs: + combi = SPLIT_KEY.join([k1, k2]) + # for example, combi is "engkey/ej/jpkey", wehere SPLIT_KEY is "/ej/" + logger.info('-- Dividing %s into %s and %s' % (combi, k1, k2)) + aux = aux.replace('%s' % combi, + '%s,%s' % (k1, k2)) + with open(fn, 'w', encoding='utf-8') as f: + f.write(aux) + return 0 + + +def divide_bbl(fn, pairs): + """divide comined bibitem(s) in bbl file. + + This code divide the combined key(s) in bbl file. + For example, the following combined bibitem(s) in bbl file + -- + \\bibitem{englishTest5/ej/japaneseTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3)\\hspace{0mm}\\\\ + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + will be converted to the following two divided bibitems. + -- + \\bibitem{englishTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3) + + \\bibitem{japaneseTest5} + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + + Parameters + ---------- + fn : str + Path to the bbl file to proceess + pairs : list of two strings + for example: [["en1", "jp1"], ["en2", "jp2"], ["en3", "jp3"]] + + Returns + ------- + int + -1 if the file to process not found, 0 if success + """ + + bbl = check_load_file(fn) + if bbl == -1: # file not found + return -1 # failed + for k1, k2 in pairs: + combi = SPLIT_KEY.join([k1, k2]) + # for example, combi is "engkey/ej/jpkey", wehere SPLIT_KEY is "/ej/" + logger.info('-- Dividing %s into %s and %s' % (combi, k1, k2)) + bbl = bbl.replace(ITEM_SEP, '\n\n\\bibitem{%s}' % k2) + bbl = bbl.replace('\\bibitem{%s}' % combi, '\\bibitem{%s}' % k1) + logger.info('-- Saving divided bbl to %s, ' % fn) + with open(fn, 'w', encoding='utf-8') as f: + f.write(bbl) + logger.info('done.') + return 0 # successfully finished + + +def find_pairs(fn, aux): + """find english/japanese pair from string in aux. + + This code find and store english/japanese pair. + Reading each line in aux strings, the engligh and japanese keys + are extracted if SPLIT_KEY is in the line. + If the combined english/japanese keys in the aux file, + the pairs are stored to the external JSON file + + Parameters + ---------- + fn : str + Path to the aux file to proceess + aux : strings in aux file + loaded string + + Returns + ------- + int + 0 if no combined keys found + num-of-pairs if successfully processed + """ + + pairs = [] + logger.info('-- ') + for line in aux.split('\n'): + if SPLIT_KEY not in line or '\\citation' not in line: + continue + # the line contains \citation and /ej/ + for ln in line.replace('\\citation{', '').replace('}', '').split(','): + # convert '\citation{hoge1/ej/hoge2}' to 'hoge1/ej/hoge2' + if len(ln.split(SPLIT_KEY)) == 2: + pairs.append(ln.split(SPLIT_KEY)) + # store as ['hoge1', 'hoge2'] pairs + logger.info('%s' % str(ln.split(SPLIT_KEY))) + if len(pairs) == 0: + logger.info('No combined keys found.') + ret = 0 + if len(pairs) > 0: + logger.info(' %d combined keys found.' % len(pairs)) + ret = pairs + save_pairs(fn, pairs) + return ret + + +def combine_aux(fn, pairs): + """combine divided citation(s) and bibcite(s) in aux file. + + This code combine the divided key(s) in aux file. + For example, the following two divided citation(s) and bibcite(s) + in aux file + -- + \\citation{englishTest7,japaneseTest7} + + \\bibcite{englishTest7,japaneseTest7}{16} + -- + will be converted to the following combined citations and bibitems. + -- + \\citation{englishTest7/ej/japaneseTest7} + + \\bibcite{englishTest7/ej/japaneseTest7}{16} + -- + + Parameters + ---------- + fn : str + Path to the aux file to proceess + pairs : list of two strings + for example: [["en1", "jp1"], ["en2", "jp2"], ["en3", "jp3"]] + + Returns + ------- + int + -1 if the file to process not found, 0 if success + """ + + aux = check_load_file(fn) + if aux == -1: # file not found + return -1 # failed + for k1, k2 in pairs: + combi = SPLIT_KEY.join([k1, k2]) + # for example, combi is "engkey/ej/jpkey", wehere SPLIT_KEY is "/ej/" + logger.info('-- Combining %s and %s to %s' % (k1, k2, combi)) + aux = aux.replace('%s,%s' % (k1, k2), '%s' % combi) + logger.info('-- Saving combined aux to %s, ' % fn) + with open(fn, 'w', encoding='utf-8') as f: + f.write(aux) + logger.info('done.') + + +def combine_bbl(fn, pairs): + """combine divided bibitem(s) in bbl file. + + This code divide the combined key(s) in bbl file. + For example, the following two divided bibitem(s) in bbl file + -- + \\bibitem{englishTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3) + + \\bibitem{japaneseTest5} + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + will be converted to the following combined citations and bibitems. + -- + \\bibitem{englishTest5/ej/japaneseTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3)\\hspace{0mm}\\\\ + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + + Parameters + ---------- + fn : str + Path to the aux file to proceess + pairs : list of two strings + for example: [["en1", "jp1"], ["en2", "jp2"], ["en3", "jp3"]] + + Returns + ------- + int + -1 if the file to process not found, 0 if success + """ + + bbl = check_load_file(fn) + if bbl == -1: # file not found + return -1 # failed + for k1, k2 in pairs: + combi = SPLIT_KEY.join([k1, k2]) + # for example, combi is "engkey/ej/jpkey", wehere SPLIT_KEY is "/ej/" + logger.info('-- Combining %s and %s to %s' % (k1, k2, combi)) + bbl = bbl.replace('\n\n\\bibitem{%s}' % k2, ITEM_SEP) + bbl = bbl.replace('\\bibitem{%s}' % k1, + '\\bibitem{%s}' % combi) + logger.info('-- Saving combined bbl to %s, ' % fn) + with open(fn, 'w', encoding='utf-8') as f: + f.write(bbl) + logger.info('done.') + + +def divide_ej_key(bn): + """divide combined english and japanese bibiteems in bbl and aux file. + + This code divide the combined key(s) in aux and bbl file. + For example, the following combined bibitem(s) in bbl file + -- + \\bibitem{englishTest5/ej/japaneseTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3)\\hspace{0mm}\\\\ + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + will be converted to the following two divided bibitems. + -- + \\bibitem{englishTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3) + + \\bibitem{japaneseTest5} + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + The following two combined citation(s) and bibcite(s) in aux file + -- + \\citation{englishTest7/ej/japaneseTest7} + + \\bibcite{englishTest7/ej/japaneseTest7}{16} + -- + will also be converted to the following combined citations and bibitems. + -- + \\citation{englishTest7} + \\citation{japaneseTest7} + + \\bibcite{englishTest7}{1} + \\bibcite{japaneseTest7}{16} + -- + The first process during LaTeX compile, there would no bbl file. + If the bbl file not exist, the dividing process would be skipped. + A list of english/japanese pairs will be extracted from aux file, + and if will be saved in the JSON file with + ".ejp" (english-japanese-pair) extension + + Parameters + ---------- + bn : str + Target file to process without extension. + if your target tex file is '/DIRNAME/main.tex' + the bn would be '/DIRNAME/main' + + Returns + ------- + int + -1 if the file to process not found + 0 if no combined keys found + num-of-pairs if successfully processed + """ + + logger.info('--') + logger.info('-- Dividing combinecd keys.') + aux = check_load_file(bn + '.aux') + if aux == -1: # aux file not found + return -1 # abort + logger.info('-- Search combined keys from %s.aux.' % bn) + pairs = find_pairs(bn + '.ejp', aux) + if pairs == 0: # no combined keys + return 0 # probably already divided + divide_aux(bn + '.aux', pairs) + divide_bbl(bn + '.bbl', pairs) + return len(pairs) + + +def combine_ej_key(bn): + """combine english and japanese bibiteems in bbl and aux file. + + This code combine the divided key(s) in aux and bbl file. + For example, the following divided bibitem(s) in bbl file + -- + \\bibitem{englishTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3) + + \\bibitem{japaneseTest5} + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + will be converted to the following two divided bibitems. + -- + \\bibitem{englishTest5/ej/japaneseTest5} + I.~Yamada, J.~Sato, S.~Tanaka, S.~Suzuki: ``Article title'', Japanese + Transaction, Vol.10, No.5, pp.45--60 (2016-3)\\hspace{0mm}\\\\ + 山田~一郎・佐藤~次郎・田中~三郎・鈴木~四郎:「文献タイトル」, + 日本語学会,Vol.10,No.5,pp.45--60(2016-3) + -- + The following two divided citation(s) and bibcite(s) in aux file + -- + \\citation{englishTest7} + \\citation{japaneseTest7} + + \\bibcite{englishTest7}{1} + \\bibcite{japaneseTest7}{16} + -- + will also be converted to the following combined citations and bibitems. + -- + \\citation{englishTest7/ej/japaneseTest7} + + \\bibcite{englishTest7/ej/japaneseTest7}{16} + -- + + Parameters + ---------- + bn : str + Target file to process without extension. + if your target tex file is '/DIRNAME/main.tex' + the bn would be '/DIRNAME/main' + + Returns + ------- + int + -1 if the file to process not found + 0 if no combined keys found + num-of-pairs if successfully processed + """ + + logger.info('--') + logger.info('-- Combining divided keys.') + pairs = check_load_file(bn + '.ejp', asjson=True) + if pairs == -1: # file not found + return -1 + if len(pairs) == 0: # no combined keys + return 0 + combine_aux(bn + '.aux', pairs) + combine_bbl(bn + '.bbl', pairs) + return len(pairs) + + +if __name__ == '__main__': + + logger = logging.getLogger() + logger.setLevel(logging.INFO) + + sh = logging.StreamHandler() + logger.addHandler(sh) + + logger.info( + 'This is python version %s ' % platform.python_version()) + logger.info( + 'mixje.py version %s (%s) by %s.' % + (FILE_VERSION, FILE_DATE, FILE_AUTHOR) + ) + logger.info('See web site: %s' % FILE_URL) + try: + fname = sys.argv[1] + logger.info('Target: %s' % fname) + except IndexError: + logger.info('Fatal error: You must assign target.') + sys.exit(0) + + sk = divide_ej_key(fname) + if sk > 0: # combined keys existed + logger.info('-- Fin, %d keys were divided.' % sk) + sys.exit(0) + elif sk < 0: # Abort + sys.exit(0) + + ck = combine_ej_key(fname) + if ck != 0: + # print('-- %d divided citation keys were successfully combined' % ck) + logger.info('-- Fin, %d keys were combined.' % ck) + sys.exit(0) + with open(sys.argv[1] + '.ejp', 'w', encoding='utf-8') as f: + json.dump([], f) + logger.info( + '-- No cmobined nor divided citation key in the aux file') + sys.exit(0) |