完全に展開された結果を単純な文字列として使用する(citet と \IfSubStr を使用)

完全に展開された結果を単純な文字列として使用する(citet と \IfSubStr を使用)

私はその問題に頭を悩ませていますが、インターネット上では助けになるような情報は何も見つかりません。

最初の問題は、私がフランス語でエッセイを書いているが、英語で書かれた記事もいくつか含める必要があり、引用スタイルが異なることです。フランス語が主な言語であるため、パッケージunsrtnat-frの参考文献スタイルを使用してnatbib、引用を「名前1」のように生成します。Name2"(2人の著者)を使用しています\citet。指定された英語部分"Name1"の通常のスタイルを復元したいと思います。そして私の解決策は、カスタムコマンドを定義することです。たとえば\encitet「 と 」による" そして "の結果\citet

さまざまな定義を試しましたが、結局その方法が理解できません... 毎回、引数の展開に問題があります。

定義したいコマンドの疑似コードは次のとおりです。

\newcommand{\encitet}[1]{%
% 1 : store the result of \citet{#1} in tmp (as a simple string)
% 2 : test if 'et al.' is found into the string
% 3 : if found then return tmp 
% 4 : else return the replacement of every " et " by " and " in tmp
}

以下は私がテストに使用する TeX ファイルです。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{trace}
\usepackage{xspace}
\usepackage{xstring}
\usepackage{etoolbox}
\usepackage{stringstrings}
\usepackage[square,numbers]{natbib}
\bibliographystyle{abbrvnat-fr}

% Here is the problem
\newcommand{\encitet}[1]{%
    \def\tmp{\expandafter\citet{#1}}%
    %\edef\tmp\expandafter{\mytemp{#1}}%
    %
    \expandafter\IfSubStr{\tmp}{et al.}{%
        \tmp%
    }{%
        \StrSubstitute{\tmp}{ et }{ and }%
    }\xspace%
}

% Example that works
\newcommand{\encitett}[1]{%
    \def\mytemp{\expandafter\citet{#1}}%
    \expandafter\ifstrequal\mytemp{#1}{a}{"a" was given}{not a}, %
    \expandafter\ifstrequal\mytemp{#1}{b}{"b" was given}{not b}%
}


\begin{document}

% Example with two authors
\encitet{einstein}

% Example with more than two authors 
\encitet{latexcompanion}


\citep{knuthwebsite}


\medskip

\bibliography{sample}

\end{document}

そしてbibファイル:

@article{einstein,
    author =       "Albert Einstein and AnotherGuy ForTheTest",
    title =        "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German})
        [{On} the electrodynamics of moving bodies]",
    journal =      "Annalen der Physik",
    volume =       "322",
    number =       "10",
    pages =        "891--921",
    year =         "1905",
    DOI =          "http://dx.doi.org/10.1002/andp.19053221004"
}

@book{latexcompanion,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The \LaTeX\ Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}

@misc{knuthwebsite,
    author    = "Donald Knuth",
    title     = "Knuth: Computers and Typesetting",
    url       = "http://www-cs-faculty.stanford.edu/\~{}uno/abcde.html"
}

コンパイルコマンド:

pdflatex test.tex && pdflatex test.tex && bibtex test && pdflatex test.tex && pdflatex test.tex

ご協力をよろしくお願いします

答え1

これは機能しません。\citet は非常に複雑なマクロであり、その出力を簡単な方法で取得することはできません。本当に natbib を使い続けたい場合 (biblatex では言語サポートが組み込まれています)、.bst ファイルを操作する必要があります。ドキュメント フォルダに別の名前で保存し、固定語を変更してコマンドを発行します。例:

FUNCTION{fr.and}{       %% le "et" entre les deux derniers auteurs
" \authorand{} "
}

その後、ドキュメント内でコマンドに適切な定義を与えることができます。

関連情報