在单个文档中使用多种 bibleref 样式的命令/宏

在单个文档中使用多种 bibleref 样式的命令/宏

我想bibleref在同一个文档中使用几种样式,因为有时我需要缩写参考(例如jerusalem样式),而在其他一些地方我需要以更文字的方式引用参考(例如default样式)。

可以通过本地改变样式来实现:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage{bibleref}
% \usepackage{indextools}
% \makeindex

\biblerefstyle{jerusalem}

\begin{document}
A reference with the style defined globally: \bibleverse{Gn}(1:1-3)

A reference using another style to make it appear as text:
\biblerefstyle{default}\bibleverse{Gn}(1:1-3)\biblerefstyle{jerusalem}

Again, a reference with the style defined globally: \bibleverse{Gn}(1:1-3)

% \printindex
\end{document}

代码结果 但是定义一个命令来\bibleversetxt自动本地更改样式会很方便。由于括号的解析,下面的代码显然不起作用:

\newcommand{\bibleversetxt}[1]{%
  \biblerefstyle{default}\bibleverse{#1}\biblerefstyle{jerusalem}}%

知道如何实现这个目标吗?


笔记:如果使用索引(\ibibleverse而不是\bibleverse),则会出现另一个问题,因为引用将出现在两种样式的索引中: 索引图像

如果解决方案也能解决这个问题那就太棒了!谢谢。

答案1

我实际上并不是一名圣经爱好者。

但我喜欢 TeXnical 挑战。;-)

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc} 
\usepackage[utf8]{inputenc}
\usepackage{bibleref}[2018/07/31]
\usepackage{indextools}
\usepackage{verbatim} % just for printing the index-files verbatim
%\usepackage{hyperref}
\makeindex


\makeatletter

% Patch for bibleref  2018/07/31 1.20 (NLCT and MR)
%
% Attempt at separating style for textual reference from style for reference in the index
% by introducing \biblerefindexstyle.
%
% \biblerefindexstyle sets the style for index-entries.
%
% This is a quick and dirty approach: With those macros that trigger processing of
% index-entries I inserted local scopes via \begingroup..\endgroup.
% Within these local scopes \biblerefstyle gets executed with the value provided as
% \biblerefindexstyle right before creating the index entries.
%
% I cannot guarantee that everything will work out correctly as I did not have
% time for in-depth study of the code.

\newcommand\@@biblerefindexstyle{}%
\newcommand\biblerefindexstyle[1]{%
  \renewcommand\@@biblerefindexstyle{#1}%
}%
\renewcommand*{\@end@@bibleverse}{%
  \if@bv@idx
    \begingroup
    \biblerefstyle{\@@biblerefindexstyle}%
    \expandafter\@do@bibleref@map\@@bv@idxsort\relax
    \ifx\@bv@idxentry\@empty
      \def\@bv@tmp{\@bv@mainidxentry}%
    \else
      \def\@bv@tmp{\@bv@mainidxentry!\@bv@chidxsort @\@bv@idxentry}%
    \fi
    \edef\@bv@tmpc{\@bv@idxpgformat}%\@bv@tmpa and \@bv@tmpb are tokens
    \ifx\@empty\@bv@tmpc%
      \@do@biblerefindex%
          {\@@bv@idxsort\relax @\@bv@tmp}%
    \else%
        \@do@biblerefindex%
            {\@@bv@idxsort\relax @\@bv@tmp|\@bv@idxpgformat}%
    \fi%
    \endgroup
    \@bv@idxfalse
  \fi
  \@bv@restore
  \bbl@ifunset{bbl@active@\string:}%
  {}%
  {\shorthandon:}%
}%
\renewcommand*{\@bible@verse}[1]{%
  \bbl@ifunset{bbl@active@\string:}%
    {}%
    {\shorthandoff:}%
  \@ifundefined{br@#1}%
  {%
    \PackageError{bibleref}{Unknown book '#1'}{}%
  }%
  {%
    \begingroup
    \biblerefstyle{\@@biblerefindexstyle}%
    \@bv@idxsort{\csname br@#1\endcsname}%
    \endgroup
    \def\@bv@chidxsort{}%
    \BRbooktitlestyle{\csname br@#1\endcsname}%
    \begingroup
    \biblerefstyle{\@@biblerefindexstyle}%
    \let\@bv@org@bookof\BRbookof
    \let\@bv@org@booknumberstyle\BRbooknumberstyle
    \let\@bv@org@epistletothe\BRepistletothe
    \let\@bv@org@epistlenumberstyle\BRepistlenumberstyle
    \def\BRbookof{\string\BRbookof\space}%
    \def\BRbooknumberstyle{\string\BRbooknumberstyle\space}%
    \def\BRepistletothe{\string\BRepistletothe\space}%
    \def\BRepistlenumberstyle{\string\BRepistlenumberstyle\space}%
    \@ifundefined{bri@#1}%
    {%
      \protected@edef\@bv@mainidxentry{%
         \protect\BRbooktitlestyle{\csname br@#1\endcsname}}%
    }%
    {%
      \protected@edef\@bv@mainidxentry{%
         \protect\BRbooktitlestyle{\csname bri@#1\endcsname}}%
    }%
    \let\BRbookof\@bv@org@bookof
    \let\BRbooknumberstyle\@bv@org@booknumberstyle
    \let\BRepistletothe\@bv@org@epistletothe
    \let\BRepistlenumberstyle\@bv@org@epistlenumberstyle
    \expandafter\endgroup
    \expandafter\def\expandafter\@bv@mainidxentry\expandafter{\@bv@mainidxentry}%
  }%
  \new@ifnextchar(%
    {\BRbkchsep\@bibleverse}%
    {\@end@@bibleverse}%
}%
\makeatletter

% Facilities for applying styles in local scopes only:

\newenvironment{biblerefscope}[1]{\biblerefstyle{#1}}{}%
\newcommand\UseBiblerefstyle[2]{\begingroup\biblerefstyle{#1}#2\endgroup}%
\newenvironment{biblerefindexscope}[1]{ \biblerefindexstyle{#1}}{}%
\newcommand\UseBiblerefindexstyle[2]{\begingroup\biblerefindexstyle{#1}#2\endgroup}%

% Set the global styles:

\biblerefstyle{jerusalem}
\biblerefindexstyle{default}

\begin{document}

References with the style defined globally: \\
\ibibleverse{Gn}(1:1-3)\\
\ibiblechvs{IICo}({12}:10-14)\\
\ibiblevs{Ex}({20}:15-17)

References using another style to make them appear as text:\\
\begin{biblerefscope}{default}%
\ibibleverse{Gn}(1:1-3)\\
\ibiblechvs{IICo}({12}:10-14)\\
\ibiblevs{Ex}({20}:15-17)
\end{biblerefscope}%

Again references with the style defined globally:\\
\ibibleverse{Gn}(1:1-3)\\
\ibiblechvs{IICo}({12}:10-14)\\
\ibiblevs{Ex}({20}:15-17)

References using another style to make them appear as text:\\
\UseBiblerefstyle{default}{%
  \ibibleverse{Gn}(1:1-3)\\
  \ibiblechvs{IICo}({12}:10-14)\\
  \ibiblevs{Ex}({20}:15-17)
}%

Again, a reference with the style defined globally:\\
\ibibleverse{Gn}(1:1-3)\\
\ibiblechvs{IICo}({12}:10-14)\\
\ibiblevs{Ex}({20}:15-17)

\printindex

\vfill
\leavevmode
\kern-\parindent
\kern-1in\kern-\hoffset\kern-\evensidemargin
\hbox to\paperwidth{\hrulefill}
\vfill
\begingroup\centering This is the .idx-file:\bigskip\par\endgroup
\leavevmode
\kern-\parindent
\kern-1in\kern-\hoffset\kern-\evensidemargin
\vbox{\hsize=\paperwidth\relax\centering
\fbox{\vbox{\hsize=.9\paperwidth \tiny\verbatiminput{\jobname.idx}}}\par}%
\vfill
\leavevmode
\kern-\parindent
\kern-1in\kern-\hoffset\kern-\evensidemargin
\hbox to\paperwidth{\hrulefill}
\vfill
\begingroup\centering This is the .ind-file:\bigskip\par\endgroup
\leavevmode
\kern-\parindent
\kern-1in\kern-\hoffset\kern-\evensidemargin
\vbox{\hsize=\paperwidth\relax\centering
\fbox{\vbox{\hsize=.4\paperwidth \tiny\verbatiminput{\jobname.ind}}}\par}%
\vfill
\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容