诗篇数据库

诗篇数据库

我想创建一本书(确切地说是一本诗篇集)。基本上这是一个数据库问题。我一方面有一个包含所有诗篇的 tex 文档(确切地说,目前它仍然是一个 word 文档),另一方面有我想要的书,我想从第一个文档中插入选定的诗篇。我不知道如何开始以保持简单。我查看了数据工具,但诗篇可以作为条目吗?或者应该为每篇将被调用的诗篇创建一个文档?如果是,我如何快速完成?我可以根据包含所有诗篇的文档中的标题调用诗篇吗?

答案1

数据库可以包含任何您想要的数据作为与键相关联的数据。即使是较长的文本。只需要一个数据库(-style 包,您可能只有一个键 --诗篇编号/名称-- 和相关数据 --文本--)包来处理它。

Linux(BSD 原版,部分工作正在移植到其他平台)strfile(1)实用程序(财富模式此处)获取由段落组成的文件并创建一个以段落为索引的文件以供随机访问,您需要对其进行破解以添加密钥。它可能会给你一些启发。

或者用某种脚本语言编写一个脚本,该脚本可以读取带有某些标记(如%% identifier行)的文本,并读取包含以下内容的文件:

identifier1
Lorem ispum dolor sit amet, ...
%
identifier2
Sed ut perspiciatis unde omnis iste natus error sit...

查找标识符并用以下文本替换。

答案2

我找到了一个解决方案,可以从由所有手掌组成的主文件中调用我需要的诗篇。因此,在 .tex 文件中,我拥有包含所有诗篇的“数据库”。每首诗篇都在一个命令中,该命令充当标识符。以下是一个例子:

\newcommand{\PsalmI}{%
Lorem ipsum...
}
\newcommand{\PsalmII}{%
Sed ut perspiciatis unde omnis iste natus error sit...
}

为了调用 psalm,我需要调用宏\PsalmI。但是,由于我调用的 psalm 是基于另一个数据库的内容,因此我创建了另一个命令,\Psalmus其名称取决于变量:

\newcommand{\Psalmus}[1]{\csname Psalm#1\endcsname}

要调用诗篇,我只需通过宏来调用它:\Psalmus{II}例如。这将调用宏\PsalmII并显示第二首诗篇。

此解决方案基于 Ulrike Fischer 的解决方案这个话题

答案3

如果使用“tex 文档”,则表示使用 LaTeX 2ε 编译的文档:

作为变体我的答案使用 Latex 代码块作为库 - 用于在多种表示中重复使用 Latex 元素(例如图形)我可以提供一个界面,其中具有可指定部分的文件具有模式

\filesection{⟨name of file-section⟩}
⟨code⟩
\endfilesection
%-------------------------------------------------------------
\filesection{⟨name of file-section⟩}
⟨code⟩
\endfilesection
%-------------------------------------------------------------
\filesection{⟨name of file-section⟩}
⟨code⟩
\endfilesection
%-------------------------------------------------------------
\endinput

使用命令输入这些文件

\inputfilesection{⟨name of file⟩}{⟨name of file-section⟩}

⟨代码⟩仅当 -command\inputfilesection\filesection-comand 具有相同的⟨文件部分的名称⟩-争论。

在这种情况下⟨代码⟩将在 verbatim-catcode-régime 下读取。然后将结果传递到\scantokens重新标记和正常处理。

多个\filesections 可以有相同的⟨文件部分的名称⟩. 在这种情况下,文件中出现的所有相关名称的文件部分均由 提供\inputfilesection

我知道的注意事项:

!!!不要在被!!!\inputfilesection调用的文件中执行操作\inputfilesection

这是一个最小工作示例,专门针对您排版诗篇的需求而定制。
在我的系统上,该示例编译没有问题。
如果您遇到问题/错误消息/不良行为,请告诉我。

%=================================================================================
%
% Via filecontents*-environment let's create an external text file
% `PsalmDatabase.tex` which contains \filesection-commands for denoting single
% portions of the file which can be imported into a document via the command
% \inputfilesection which in turn is defined in the code below.
%
% The external text file PsalmDatabase.tex is created on the fly via
% filecontents*- environment so that it is ensured that it is available when this
% example is compiled. Instead of doing it this way, you can also maintain
% PsalmDatabase.tex  as a separate file which is stored in a place where it can
% be foud by LaTeX. 
%
%\begin{filecontents*}[overwrite]{PsalmDatabase.tex}
\begin{filecontents*}{PsalmDatabase.tex}
\filesection{Psalm 1}
[This is whatsoever TeX-code for typesetting psalm 1.]
\section*{Psalm 1}
\begin{verbatim*}
Some verbatim material in 
code for typesetting psalm 1.
\end{verbatim*}
\endfilesection
%-------------------------------------------------------------
\filesection{Psalm 2}
[This is whatsoever TeX-code for typesetting psalm 2.]
\section*{Psalm 2}
This is psalm 2.

This is psalm 2.
\endfilesection
%-------------------------------------------------------------
\filesection{Psalm 3}
[This is whatsoever TeX-code for typesetting psalm 2.]
\section*{Psalm 3}
This is the third psalm.
\begin{verbatim*}
Some verbatim material
in code for typesetting psalm 3.
\end{verbatim*}
\endfilesection
%-------------------------------------------------------------
\endinput
\end{filecontents*}

%=================================================================================
%
\makeatletter
\@ifundefined{NewDocumentCommand}{\RequirePackage{xparse}}{}%
%///// begin of code that could go into a package / .sty-file//////////////////
\NewDocumentCommand\inputfilesection{mm}{%
  \def\@stringincommand{#2}%
  \input{#1}%
}%
\newcommand\@stringincommand{}%
\newcommand\@stringinfile{}%
\NewDocumentCommand\filesection{m}{%
  \begingroup
  \let\do\@makeother\dospecials
  \do\^^I%
  \do\^^M%
  \@filesection{#1}%
}%
\begingroup
\newcommand\@filesection[2]{%
  \endgroup
  \def\@filesection##1##2#1{%
     \def\@stringinfile{##1}%
     \expandafter\endgroup
     \ifx\@stringinfile\@stringincommand\expandafter\@firstofone\else\expandafter\@gobble\fi
     {%
       \begingroup
       \newlinechar=\endlinechar
       \scantokens\expandafter\expandafter\expandafter{%
       \expandafter\expandafter\expandafter\endgroup
       \UD@RemoveLeadingNTrailingCarriageReturn{##2}#2}%
     }\ignorespaces
  }%
}%
\@firstofone{%
  \let\do\@makeother\dospecials
  \catcode`\{=1 %
  \catcode`\}=2 %
  \@filesection
}{\endfilesection}{\ignorespaces%}%
%=================================================================================
% Begin of code for removing one leading and one trailing explicit
% <carriage-return>-character-token of catcode 12(other) from _verbatimized_ 
% argument
%=================================================================================
\@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is empty>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
  \romannumeral\expandafter\@secondoftwo\string{\expandafter
  \@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
  \@secondoftwo\string}\expandafter\@firstoftwo\expandafter{\expandafter
  \@secondoftwo\string}\expandafter\UD@stopromannumeral\@secondoftwo}{%
  \expandafter\UD@stopromannumeral\@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
\begingroup
\@makeother\^^M%
\@firstofone{%
  \endgroup%
  %%=============================================================================
  %% Check whether_verbatimized_ argument has a leading explicit 
  %% <carriage-return>-character-token of catcode 12(other):
  %%-----------------------------------------------------------------------------
  %% \UD@CheckWhetherLeadingCarriageReturn{<Argument which is to be checked>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       1st token is an explicit <carriage-
  %%                                       return>-character-token of 
  %%                                       catcode 12(other)>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       1st token is not an explicit
  %%                                       <carriage-return>-character-token of 
  %%                                       catcode 12(other)>}%
  \newcommand\UD@CheckWhetherLeadingCarriageReturn[1]{%
    \UD@@CheckWhetherLeadingCarriageReturn\UD@SelDom#1\UD@SelDom^^M\UD@@SelDom%
  }%
  \@ifdefinable\UD@@CheckWhetherLeadingCarriageReturn{%
    \long\def\UD@@CheckWhetherLeadingCarriageReturn#1\UD@SelDom^^M#2\UD@@SelDom{%
      \UD@CheckWhetherNull{#2}{\@secondoftwo}{\@firstoftwo}%
    }%
  }%
  %%-----------------------------------------------------------------------------
  %% Check whether_verbatimized_ argument having a leading explicit <carriage-
  %% return>-character-token of catcode 12(other) consists only of such tokens:
  %%-----------------------------------------------------------------------------
  %% \UD@CheckWhetherOnlyCarriageReturn{<Argument which is to be checked and 
  %%                                    which is known to have a leading explicit
  %%                                    <carriage-return>-character-token of
  %%                                    catcode 12(other)>}%
  %%                                   {<Tokens to be delivered in case <argument
  %%                                    which is to be checked> consists only
  %%                                    of explicit <carriage-return>-character-
  %%                                    tokens of catcode 12(other)>}%
  %%                                   {<Tokens to be delivered in case <argument
  %%                                    which is to be checked> does not consist
  %%                                    only of explicit <carriage-return>-
  %%                                    character-tokens of catcode 12(other)>}%
  \newcommand\UD@CheckWhetherOnlyCarriageReturn[1]{%
    \UD@CheckWhetherLeadingCarriageReturn{#1}{%
      \expandafter\UD@CheckWhetherOnlyCarriageReturn%
      \expandafter{\UD@@TrimLeadingCarriageReturn#1}%
    }{%
      \UD@CheckWhetherNull{#1}{\@firstoftwo}{\@secondoftwo}%
    }%
  }%
  %%-----------------------------------------------------------------------------
  %% Remove one leading explicit <carriage-return>-character-token of 
  %% catcode 12(other) from _verbatimized_ argument:
  %%-----------------------------------------------------------------------------
  \@ifdefinable\UD@@TrimLeadingCarriageReturn{%
    \long\def\UD@@TrimLeadingCarriageReturn^^M{}%
  }%
  %%-----------------------------------------------------------------------------
  %% Check whether_verbatimized_ argument has a trailing explicit 
  %% <carriage-return>-character-token of catcode 12(other):
  %%-----------------------------------------------------------------------------
  %% \UD@CheckWhetherTrailingCarriageReturn{<Argument which is to be checked>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       last token is an explicit <carriage-
  %%                                       return>-character-token of 
  %%                                       catcode 12(other)>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       last token is not an explicit
  %%                                       <carriage-return>-character-token of 
  %%                                       catcode 12(other)>}%
  \newcommand\UD@CheckWhetherTrailingCarriageReturn[1]{%
    \UD@@CheckWhetherTrailingCarriageReturn#1\UD@SelDom^^M\UD@SelDom\UD@@SelDom%
  }%
  \@ifdefinable\UD@@CheckWhetherTrailingCarriageReturn{%
    \long\def\UD@@CheckWhetherTrailingCarriageReturn#1^^M\UD@SelDom#2\UD@@SelDom{%
      \UD@CheckWhetherNull{#2}{\@secondoftwo}{\@firstoftwo}%
    }%
  }%
  %%-----------------------------------------------------------------------------
  %% Remove one trailing explicit <carriage-return>-character-token of 
  %% catcode 12(other) from _verbatimized_ argument:
  %%-----------------------------------------------------------------------------
  \newcommand\UD@TrimTrailingCarriageReturn[1]{%
     \UD@@TrimTrailingCarriageReturn#1\UD@SelDom%
  }%
  \@ifdefinable\UD@@TrimTrailingCarriageReturn{%
    \long\def\UD@@TrimTrailingCarriageReturn#1^^M\UD@SelDom{#1}%
  }%
  %%-----------------------------------------------------------------------------
  %% Remove one leading and one trailing explicit <carriage-return>-character-
  %% token of catcode 12(other) from _verbatimized_ argument if present.
  %% In the edge case of the _verbatimized_ argument consisting only of explicit
  %% <carriage-return>-character-tokens of catcode 12(other) remove only one of 
  %% them.
  %% Due to \romannumeral-expansion the result is delivered in 2 expansion-steps:
  %%-----------------------------------------------------------------------------
  \newcommand\UD@RemoveLeadingNTrailingCarriageReturn[1]{%
    \romannumeral%
    \UD@CheckWhetherLeadingCarriageReturn{#1}{%
      \UD@CheckWhetherTrailingCarriageReturn{#1}{%
         \UD@CheckWhetherOnlyCarriageReturn{#1}{%
           \expandafter\UD@stopromannumeral\UD@@TrimLeadingCarriageReturn#1%
         }{%
           \expandafter\expandafter\expandafter\expandafter\expandafter%
           \expandafter\expandafter\UD@stopromannumeral\expandafter%
           \UD@TrimTrailingCarriageReturn\expandafter{\UD@@TrimLeadingCarriageReturn#1}%
         }%
      }{%
        \expandafter\UD@stopromannumeral\UD@@TrimLeadingCarriageReturn#1%
      }%
    }{%
      \UD@CheckWhetherTrailingCarriageReturn{#1}{%
        \expandafter\expandafter\expandafter\UD@stopromannumeral%
        \UD@TrimTrailingCarriageReturn{#1}%
      }{\UD@stopromannumeral#1}%
    }%
  }%
}%
%================================================================================
% End of code for removing one leading and one trailing explicit
% <carriage-return>-character-token of catcode 12(other) from _verbatimized_ 
% argument
%================================================================================
%///// end of code that could go into a package / .sty-file////////////////////
\makeatother

%================================================================================
% A document where the command \inputfilesection, whose definition forms the code 
% that could go into a package / .sty-file, is used for inputting sections/
% portions of the external file  `PsalmDatabase.tex`
% 

\documentclass{article}

\begin{document}

\noindent\textbf{Here comes Psalm 1:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 1}

\bigskip\hrule\bigskip\noindent\textbf{That is Psalm 2:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 2}

\bigskip\hrule\bigskip\noindent\textbf{Now let's have Psalm 3:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 3}

\bigskip\hrule\bigskip\noindent\textbf{Here comes Psalm 1 again:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 1}

\bigskip\hrule\bigskip\noindent\textbf{That is Psalm 2 again:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 2}

\bigskip\hrule\bigskip\noindent\textbf{Now let's have Psalm 3 again:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 3}

\end{document}

pdf 输出如下所示:

在此处输入图片描述

如果您希望将其拆分为多个文件,您可以执行以下操作:

文件PsalmDatabase.tex

\filesection{Psalm 1}
[This is whatsoever TeX-code for typesetting psalm 1.]
\section*{Psalm 1}
\begin{verbatim*}
Some verbatim material in 
code for typesetting psalm 1.
\end{verbatim*}
\endfilesection
%-------------------------------------------------------------
\filesection{Psalm 2}
[This is whatsoever TeX-code for typesetting psalm 2.]
\section*{Psalm 2}
This is psalm 2.

This is psalm 2.
\endfilesection
%-------------------------------------------------------------
\filesection{Psalm 3}
[This is whatsoever TeX-code for typesetting psalm 2.]
\section*{Psalm 3}
This is the third psalm.
\begin{verbatim*}
Some verbatim material
in code for typesetting psalm 3.
\end{verbatim*}
\endfilesection
%-------------------------------------------------------------
\endinput

文件inputfilesections.sty

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{inputfilesections}[2022/07/18 v0.01 import portions of .tex-files]
\@ifundefined{NewDocumentCommand}{\RequirePackage{xparse}}{}%
\NewDocumentCommand\inputfilesection{mm}{%
  \def\@stringincommand{#2}%
  \input{#1}%
}%
\newcommand\@stringincommand{}%
\newcommand\@stringinfile{}%
\NewDocumentCommand\filesection{m}{%
  \begingroup
  \let\do\@makeother\dospecials
  \do\^^I%
  \do\^^M%
  \@filesection{#1}%
}%
\begingroup
\newcommand\@filesection[2]{%
  \endgroup
  \def\@filesection##1##2#1{%
     \def\@stringinfile{##1}%
     \expandafter\endgroup
     \ifx\@stringinfile\@stringincommand\expandafter\@firstofone\else\expandafter\@gobble\fi
     {%
       \begingroup
       \newlinechar=\endlinechar
       \scantokens\expandafter\expandafter\expandafter{%
       \expandafter\expandafter\expandafter\endgroup
       \UD@RemoveLeadingNTrailingCarriageReturn{##2}#2}%
     }\ignorespaces
  }%
}%
\@firstofone{%
  \let\do\@makeother\dospecials
  \catcode`\{=1 %
  \catcode`\}=2 %
  \@filesection
}{\endfilesection}{\ignorespaces%}%
%=================================================================================
% Begin of code for removing one leading and one trailing explicit
% <carriage-return>-character-token of catcode 12(other) from _verbatimized_ 
% argument
%=================================================================================
\@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is empty>}%
%%                     {<Tokens to be delivered in case that argument
%%                       which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
  \romannumeral\expandafter\@secondoftwo\string{\expandafter
  \@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
  \@secondoftwo\string}\expandafter\@firstoftwo\expandafter{\expandafter
  \@secondoftwo\string}\expandafter\UD@stopromannumeral\@secondoftwo}{%
  \expandafter\UD@stopromannumeral\@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
\begingroup
\@makeother\^^M%
\@firstofone{%
  \endgroup%
  %%=============================================================================
  %% Check whether_verbatimized_ argument has a leading explicit 
  %% <carriage-return>-character-token of catcode 12(other):
  %%-----------------------------------------------------------------------------
  %% \UD@CheckWhetherLeadingCarriageReturn{<Argument which is to be checked>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       1st token is an explicit <carriage-
  %%                                       return>-character-token of 
  %%                                       catcode 12(other)>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       1st token is not an explicit
  %%                                       <carriage-return>-character-token of 
  %%                                       catcode 12(other)>}%
  \newcommand\UD@CheckWhetherLeadingCarriageReturn[1]{%
    \UD@@CheckWhetherLeadingCarriageReturn\UD@SelDom#1\UD@SelDom^^M\UD@@SelDom%
  }%
  \@ifdefinable\UD@@CheckWhetherLeadingCarriageReturn{%
    \long\def\UD@@CheckWhetherLeadingCarriageReturn#1\UD@SelDom^^M#2\UD@@SelDom{%
      \UD@CheckWhetherNull{#2}{\@secondoftwo}{\@firstoftwo}%
    }%
  }%
  %%-----------------------------------------------------------------------------
  %% Check whether_verbatimized_ argument having a leading explicit <carriage-
  %% return>-character-token of catcode 12(other) consists only of such tokens:
  %%-----------------------------------------------------------------------------
  %% \UD@CheckWhetherOnlyCarriageReturn{<Argument which is to be checked and 
  %%                                    which is known to have a leading explicit
  %%                                    <carriage-return>-character-token of
  %%                                    catcode 12(other)>}%
  %%                                   {<Tokens to be delivered in case <argument
  %%                                    which is to be checked> consists only
  %%                                    of explicit <carriage-return>-character-
  %%                                    tokens of catcode 12(other)>}%
  %%                                   {<Tokens to be delivered in case <argument
  %%                                    which is to be checked> does not consist
  %%                                    only of explicit <carriage-return>-
  %%                                    character-tokens of catcode 12(other)>}%
  \newcommand\UD@CheckWhetherOnlyCarriageReturn[1]{%
    \UD@CheckWhetherLeadingCarriageReturn{#1}{%
      \expandafter\UD@CheckWhetherOnlyCarriageReturn%
      \expandafter{\UD@@TrimLeadingCarriageReturn#1}%
    }{%
      \UD@CheckWhetherNull{#1}{\@firstoftwo}{\@secondoftwo}%
    }%
  }%
  %%-----------------------------------------------------------------------------
  %% Remove one leading explicit <carriage-return>-character-token of 
  %% catcode 12(other) from _verbatimized_ argument:
  %%-----------------------------------------------------------------------------
  \@ifdefinable\UD@@TrimLeadingCarriageReturn{%
    \long\def\UD@@TrimLeadingCarriageReturn^^M{}%
  }%
  %%-----------------------------------------------------------------------------
  %% Check whether_verbatimized_ argument has a trailing explicit 
  %% <carriage-return>-character-token of catcode 12(other):
  %%-----------------------------------------------------------------------------
  %% \UD@CheckWhetherTrailingCarriageReturn{<Argument which is to be checked>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       last token is an explicit <carriage-
  %%                                       return>-character-token of 
  %%                                       catcode 12(other)>}%
  %%                                      {<Tokens to be delivered in case
  %%                                       <argument which is to be checked>'s
  %%                                       last token is not an explicit
  %%                                       <carriage-return>-character-token of 
  %%                                       catcode 12(other)>}%
  \newcommand\UD@CheckWhetherTrailingCarriageReturn[1]{%
    \UD@@CheckWhetherTrailingCarriageReturn#1\UD@SelDom^^M\UD@SelDom\UD@@SelDom%
  }%
  \@ifdefinable\UD@@CheckWhetherTrailingCarriageReturn{%
    \long\def\UD@@CheckWhetherTrailingCarriageReturn#1^^M\UD@SelDom#2\UD@@SelDom{%
      \UD@CheckWhetherNull{#2}{\@secondoftwo}{\@firstoftwo}%
    }%
  }%
  %%-----------------------------------------------------------------------------
  %% Remove one trailing explicit <carriage-return>-character-token of 
  %% catcode 12(other) from _verbatimized_ argument:
  %%-----------------------------------------------------------------------------
  \newcommand\UD@TrimTrailingCarriageReturn[1]{%
     \UD@@TrimTrailingCarriageReturn#1\UD@SelDom%
  }%
  \@ifdefinable\UD@@TrimTrailingCarriageReturn{%
    \long\def\UD@@TrimTrailingCarriageReturn#1^^M\UD@SelDom{#1}%
  }%
  %%-----------------------------------------------------------------------------
  %% Remove one leading and one trailing explicit <carriage-return>-character-
  %% token of catcode 12(other) from _verbatimized_ argument if present.
  %% In the edge case of the _verbatimized_ argument consisting only of explicit
  %% <carriage-return>-character-tokens of catcode 12(other) remove only one of 
  %% them.
  %% Due to \romannumeral-expansion the result is delivered in 2 expansion-steps:
  %%-----------------------------------------------------------------------------
  \newcommand\UD@RemoveLeadingNTrailingCarriageReturn[1]{%
    \romannumeral%
    \UD@CheckWhetherLeadingCarriageReturn{#1}{%
      \UD@CheckWhetherTrailingCarriageReturn{#1}{%
         \UD@CheckWhetherOnlyCarriageReturn{#1}{%
           \expandafter\UD@stopromannumeral\UD@@TrimLeadingCarriageReturn#1%
         }{%
           \expandafter\expandafter\expandafter\expandafter\expandafter%
           \expandafter\expandafter\UD@stopromannumeral\expandafter%
           \UD@TrimTrailingCarriageReturn\expandafter{\UD@@TrimLeadingCarriageReturn#1}%
         }%
      }{%
        \expandafter\UD@stopromannumeral\UD@@TrimLeadingCarriageReturn#1%
      }%
    }{%
      \UD@CheckWhetherTrailingCarriageReturn{#1}{%
        \expandafter\expandafter\expandafter\UD@stopromannumeral%
        \UD@TrimTrailingCarriageReturn{#1}%
      }{\UD@stopromannumeral#1}%
    }%
  }%
}%
%================================================================================
% End of code for removing one leading and one trailing explicit
% <carriage-return>-character-token of catcode 12(other) from _verbatimized_ 
% argument
\endinput

文件document.tex

\documentclass{article}
\usepackage{inputfilesections}

\begin{document}

\noindent\textbf{Here comes Psalm 1:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 1}

\bigskip\hrule\bigskip\noindent\textbf{That is Psalm 2:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 2}

\bigskip\hrule\bigskip\noindent\textbf{Now let's have Psalm 3:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 3}

\bigskip\hrule\bigskip\noindent\textbf{Here comes Psalm 1 again:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 1}

\bigskip\hrule\bigskip\noindent\textbf{That is Psalm 2 again:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 2}

\bigskip\hrule\bigskip\noindent\textbf{Now let's have Psalm 3 again:}\bigskip

\inputfilesection{PsalmDatabase.tex}{Psalm 3}

\end{document}

如果文件部分中的某些代码需要在文档前言中加载某些包,则文件PsalmDatabase.tex可以包含文件部分“RequiredPackages”,而该文件部分又包含相应的\RequirePackage- 或 -\usepackage命令。这样,如果文件部分中的某些代码需要某些包,则您无需记住加载这些包。相反,只需在文档前言中执行 即可\inputfilesection{PsalmDatabase.tex}{RequiredPackages}

相关内容