编辑

编辑

我已经用 LaTeX(使用 Overleaf)准备了法学院课程笔记/大纲。我有一门学校课程,其中既要测试美国大多数州的某一学科的一般法律,也要测试我所在州的特定法律例外情况。但是当我毕业后参加律师资格考试时,我只会测试一般法律,而不会测试州特定的例外情况。

因此,当我打印笔记用于学校期末考试时,我希望以某种方式标记特定州的部分,以便将它们与一般规则区分开来。(对于标记的文本,我可能会使用不同的字体颜色、突出显示、加框——我还没有确定。)但我还希望能够打印一份没有任何标记的州特定例外的笔记版本,以便在毕业后使用,那时我只是在准备律师资格考试,不需要知道特定州的例外情况。

实现此目标的最佳方法是什么?目标是 (1) 区分标记文本,以及 (2) 能够打印排除所有标记文本的版本。

编辑以添加示例:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage{color,soul} % for color and highlighting
\usepackage[shortlabels]{enumitem} % change enum styles
\usepackage{graphicx}

\begin{document}
    \subsubsection{Burden Shifting}
    \begin{itemize}
        \item Will contestant entitled to presumption of undue influence by showing:
        \begin{enumerate}
            \item \textit{confidential relationship} between the alleged influencer and the testator;
                \begin{itemize}
                    \item fiduciary
                    \item attorney
                    \item dominant control
                \end{itemize}
            \item and the presence of one or more \textit{suspicious circumstances}
                \begin{itemize}
                    \item unnatural disposition in will
                    \item secrecy
                    \item testator's susceptibility to influence
                \end{itemize}
        \end{enumerate}
        \item \hl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
    \end{itemize}
\end{document}

底部关于德克萨斯州的突出显示部分最好加上标签,这样当我想打印排除德克萨斯州例外情况的版本时,就可以省略它。我希望使用一个可用于设置格式的自定义标签或进行简单的调整以完全省略。

答案1

您可以非常轻松地将其设置为突出显示与不同字体或不同字体颜色与无。框线会比较棘手,因为您可能不知道框线应该有多宽,因为您可能从一行的中间开始。这在段落分隔符等处也会很麻烦。(这有点取决于例外有多长,但由于这是法律,我怀疑它们可能会有些长!)

处理简单情况的一个非常简单的方法是,在序言中定义一个自定义命令来执行突出显示或其他操作。如果您想更改它的功能,请更改序言中的定义。如果您想删除状态异常,请注释掉定义的内容,这样它就可以吸收其参数而不执行任何操作。

然后你可以写说,

\tchl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}

\tchl并且可以通过改变序言中的定义来轻松改变这是否产生任何东西,如果产生的话,它的格式如何。

其定义等同\hl于你的例子,

\NewDocumentCommand \tchl { +m }{%
  \hl{#1}% comment out this line to drop the exceptions
}

其定义等同于 \hl{}

改变定义以使用蓝色无衬线字体,

\NewDocumentCommand \tchl { +m }{%
  {\sffamily\color{blue}#1}% comment out this line to drop the exceptions
}

重新定义为使用蓝色无衬线字体

注释掉这个定义,

\NewDocumentCommand \tchl { +m }{%
%   \hl{#1}% comment out this line to drop the exceptions
}

定义内容被注释掉

完整代码:

\documentclass[letterpaper]{report}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage{color,soul} % for color and highlighting
\usepackage[shortlabels]{enumitem} % change enum styles
\usepackage{graphicx}

\NewDocumentCommand \tchl { +m }{%
  \hl{#1}% leave uncommented for highlighting ; comment out to drop exceptions ; comment out and uncomment next line for blue sans-serif
%   {\sffamily\color{blue}#1}% uncomment line for blue sans-serif
}

\begin{document}
\subsubsection{Burden Shifting}
\begin{itemize}
  \item Will contestant entitled to presumption of undue influence by showing:
  \begin{enumerate}
    \item \textit{confidential relationship} between the alleged influencer and the testator;
    \begin{itemize}
      \item fiduciary
      \item attorney
      \item dominant control
    \end{itemize}
    \item and the presence of one or more \textit{suspicious circumstances}
    \begin{itemize}
      \item unnatural disposition in will
      \item secrecy
      \item testator's susceptibility to influence
    \end{itemize}
  \end{enumerate}
  \item \tchl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
\end{itemize}
\end{document}

编辑

可能最好进行定义,比如说,\tchlitem处理命令插入的情况\item

\tchl 的变体

定义:

\NewDocumentCommand \tchl { +m }{%
%   \hl{#2}% leave uncommented for highlighting ; comment out to drop exceptions ; comment out and uncomment next line for blue sans-serif
  {\sffamily\color{blue}#1}% uncomment line for blue sans-serif
}
\NewDocumentCommand \tchlitem { +m }{%
  \item {\bfseries\color{magenta}#1}%
}

内容:

  \tchl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
  \tchlitem{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
  \tchl{\item Texas: there is no burden shifting and the contestant must establish each element with evidence.}

除非有特殊原因,否则我不建议使用不同的颜色,但我想明确哪个命令负责输出中的哪一行。不要尝试\item在内容中包含\hl{}。突出显示的文本容易​​损坏并会出现错误。如果您想要一个强大的解决方案,请坚持使用字体和颜色更改。

答案2

使用文档条可以采用不同的方法来处理此事。

文档条包是一种从一个(一组)主文件派生不同 .tex 输入文件的方法。在主文件中,您可以放置​​所谓的标签。这些标签用于确定主文件中标记的文本部分将被复制到的派生文件。

在主文件的头部和另一个文件中,您都可以使用所谓的\generate指令来创建从主文件派生的文件。

有关更多信息文档条可以在 CTAN 找到:
https://ctan.org/pkg/docstrip

如果将以下示例保存为文件,并且文件名不是WithoutTexasNotes.tex并且除此以外AlsoWithTexasNotes.tex并使用特克斯或者pdftex或者乳胶或者pdflatex,将创建两个新文件,其中一个名为WithoutTexasNotes.tex,另一个叫做AlsoWithTexasNotes.tex

%<*ignore>
% Section with docstrip directives for generating different 
% .tex-input-files:
\input docstrip

\declarepreamble\WithoutStuffThatIsSpecificToTexasOnly

_________________________________________________________________

Course notes, release without notes that are specific to Texas only.

Use pdflatex/pdftexify for compiling this file.

\endpreamble

\declarepreamble\AlsoWithStuffThatIsSpecificToTexasOnly

________________________________________________________________________________________________

Course notes, release also with notes that are specific to Texas only.

Use pdflatex/pdftexify for compiling this file.

\endpreamble

\generate{%
  \nopostamble
%
  \usepreamble\WithoutStuffThatIsSpecificToTexasOnly
  \file{WithoutTexasNotes.tex}{\from{\jobname.tex}{StuffThatIsSpecificToAllStates}}%
%
  \usepreamble\AlsoWithStuffThatIsSpecificToTexasOnly
  \file{AlsoWithTexasNotes.tex}{\from{\jobname.tex}{StuffThatIsSpecificToAllStates,StuffThatIsSpecificToTexasOnly}}%
}%
% Here you can probably insert \write18-calls suitable for your platform
% for calling pdflatex from console for compiling the files
% just generated -- something like:
%    \immediate\write18{pdflatex teacher.tex}
%    \immediate\write18{pdflatex students.tex}
%    \immediate\write18{pdftexify teacher.tex}
%    \immediate\write18{pdftexify students.tex}
%
\csname stop\endcsname % <- end this TeX-run in case you used (pdf)LaTeX
                       %    for generating the files.
%
\bye % <- end this TeX-run in case you used (pdf)TeX for generating the 
%    %    files.
%
%</ignore>
% Section containing the actual LaTeX document, with tags for
% generating different variants with different target groups
%<*StuffThatIsSpecificToAllStates>
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage{color,soul} % for color and highlighting
\usepackage[shortlabels]{enumitem} % change enum styles
\usepackage{graphicx}

\begin{document}
    \subsubsection{Burden Shifting}
    \begin{itemize}
        \item Will contestant entitled to presumption of undue influence by showing:
        \begin{enumerate}
            \item \textit{confidential relationship} between the alleged influencer and the testator;
                \begin{itemize}
                    \item fiduciary
                    \item attorney
                    \item dominant control
                \end{itemize}
            \item and the presence of one or more \textit{suspicious circumstances}
                \begin{itemize}
                    \item unnatural disposition in will
                    \item secrecy
                    \item testator's susceptibility to influence
                \end{itemize}
        \end{enumerate}
%<*StuffThatIsSpecificToTexasOnly>
        \item \hl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
%</StuffThatIsSpecificToTexasOnly>
%<StuffThatIsSpecificToTexasOnly>        \item \hl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
    \end{itemize}
\end{document}
%</StuffThatIsSpecificToAllStates>

的内容WithoutTexasNotes.tex是:

%%
%% This is file `WithoutTexasNotes.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% CourseNotes.tex  (with options: `StuffThatIsSpecificToAllStates')
%% 
%% _________________________________________________________________
%% 
%% Course notes, release without notes that are specific to Texas only.
%% 
%% Use pdflatex/pdftexify for compiling this file.
%% 
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage{color,soul} % for color and highlighting
\usepackage[shortlabels]{enumitem} % change enum styles
\usepackage{graphicx}

\begin{document}
    \subsubsection{Burden Shifting}
    \begin{itemize}
        \item Will contestant entitled to presumption of undue influence by showing:
        \begin{enumerate}
            \item \textit{confidential relationship} between the alleged influencer and the testator;
                \begin{itemize}
                    \item fiduciary
                    \item attorney
                    \item dominant control
                \end{itemize}
            \item and the presence of one or more \textit{suspicious circumstances}
                \begin{itemize}
                    \item unnatural disposition in will
                    \item secrecy
                    \item testator's susceptibility to influence
                \end{itemize}
        \end{enumerate}
    \end{itemize}
\end{document}

的内容AlsoWithTexasNotes.tex是:

%%
%% This is file `AlsoWithTexasNotes.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% CourseNotes.tex  (with options: `StuffThatIsSpecificToAllStates,StuffThatIsSpecificToTexasOnly')
%% 
%% ________________________________________________________________________________________________
%% 
%% Course notes, release also with notes that are specific to Texas only.
%% 
%% Use pdflatex/pdftexify for compiling this file.
%% 
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage{color,soul} % for color and highlighting
\usepackage[shortlabels]{enumitem} % change enum styles
\usepackage{graphicx}

\begin{document}
    \subsubsection{Burden Shifting}
    \begin{itemize}
        \item Will contestant entitled to presumption of undue influence by showing:
        \begin{enumerate}
            \item \textit{confidential relationship} between the alleged influencer and the testator;
                \begin{itemize}
                    \item fiduciary
                    \item attorney
                    \item dominant control
                \end{itemize}
            \item and the presence of one or more \textit{suspicious circumstances}
                \begin{itemize}
                    \item unnatural disposition in will
                    \item secrecy
                    \item testator's susceptibility to influence
                \end{itemize}
        \end{enumerate}
        \item \hl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
        \item \hl{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
    \end{itemize}
\end{document}

答案3

要切换文本,我会在 latex 中使用标志和if条件。我会单独保留 @cfr 提供的解决方案,这样您还可以突出显示普通文本,而不仅仅是列表。因此,您将有三个命令,tch用于tchitem突出显示文本并specificText选择是否隐藏文本。如果您想要一个命令,并且只使用列表,那么请随意将tchitem和合并specificText为一个。

标志\showtext控制代码是否显示(如果设置为)true或不显示(如果设置为)false。我必须提到,这样做是告诉 latex 不要看到条件中包含的代码部分if

showtext设置为true在此处输入图片描述

showtext设置为false

在此处输入图片描述

代码:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper,margin=1in]{geometry}
\usepackage{color,soul} % for color and highlighting
\usepackage[shortlabels]{enumitem} % change enum styles
\usepackage{graphicx}

\NewDocumentCommand \tchlitem { +m }{% % Credit to @cfr
    \item {\bfseries\color{magenta}#1}%
}

\newif\ifshowtext % Creates "flag"
\showtexttrue        % Uncomment to show text enclosed in the command \specificText
%\showtextfalse   % Uncomment to hide text enclosed in the command \specificText

\newcommand{\specificText}[1]{% Wraps target text.
    \ifshowtext
    #1
    \fi
}

\begin{document}
    \subsubsection{Burden Shifting}
    \begin{itemize}
        \item Will contestant entitled to presumption of undue influence by showing:
        \begin{enumerate}
            \item \textit{confidential relationship} between the alleged influencer and the testator;
            \specificText{% < ----
            \begin{itemize}
                \tchlitem  {fiduciary}
                \tchlitem  {attorney}
                \tchlitem  {dominant control}
            \end{itemize}
        }% < ----
            \item and the presence of one or more \textit{suspicious circumstances}
            \begin{itemize}
                \item unnatural disposition in will
                \item secrecy
                \item testator's susceptibility to influence
            \end{itemize}
        \end{enumerate}
        \specificText{% < ----
        \tchlitem{Texas: there is no burden shifting and the contestant must establish each element with evidence.}
        }% < ----
    \end{itemize}
\end{document}

相关内容