检测文本的实际开始

检测文本的实际开始

我有条件,有时会被抑制,如果它被排版则需要注意。

如果条件文本以在文本实际开始之前添加垂直空间的环境开始,则\tikzmark需要调整位置。请注意,在段落模式下,文本被适当标记,但以 , 开头时align*,或enumerate绘制的括号太大:

在此处输入图片描述

因此,我需要能够检测文本开始和结束的位置,这确实不是包括任何前导或尾随空格。

笔记:

  • 将 移动\MarkThisTextalign*或内enumerate对我来说不起作用,因为整个块可能会被抑制,在这种情况下,我需要抑制环境的begin,如果直到 之后才开始,end这将会很困难。\MarkThisText\begin{align*}
  • 我考虑过用align和类型环境设置一个标志,但是如果或恰好嵌入在的中间,enumerate那么就会失败。alignenumerate\MarkThisText

代码:

\documentclass{article}
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}

\newcommand{\DrawBrace}[3][]{%
    \begin{tikzpicture}[overlay,remember picture]
        \coordinate (Top) at 
            ($(#2.north  -| current page.south east)+(-4.5cm,0.25\baselineskip)$);
        \coordinate (Bottom) at 
            ($(#3.south -| current page.south east)+(-4.5,-0.25\baselineskip)$);
                \draw [
                    line width=1.0pt, 
                    decoration={brace, amplitude=0.30em}, 
                    decorate, #1,
                    ] (Top) -- (Bottom)
                    node[rotate=90, midway, below] {Note};
    \end{tikzpicture}%
}

\newcommand{\MarkThisText}[2][]{%
    %% conditions to determine if this text is to be suppressed omitted
    %% \iftoggle{SuppressThisText}{}{%
        \tikzmark{Start}%
            \color{#1}%
            #2%
            \color{black}%
        \tikzmark{End}%
        \DrawBrace[#1]{Start}{End}%
    %% } % end \iftoggle{DisplayThisText}
}%

\begin{document}
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at dignissim eros. 
 Morbi faucibus sit amet felis a accumsan.  Aliquam 
 dapibus pellentesque dui, vitae aliquam turpis semper eget.
 
 \MarkThisText[blue]{% 
     Donec egestas leo nibh, at malesuada leo congue non. 
     Cras laoreet lectus sed tortor laoreet, ac aliquet nibh condimentum. 
     \begin{align*}
         F &= ma \\
         \implies E &= mc^2
     \end{align*}
     Nam elementum ante non nunc facilisis porttitor. Nullam non suscipit lorem. 
     Sed arcu dui, accumsan et pretium dictum, venenatis id metus.%
 }
 
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at dignissim eros. 
 Morbi faucibus sit amet felis a accumsan.  Aliquam 
 dapibus pellentesque dui, vitae aliquam turpis semper eget.


Text before \verb|align| should \emph{not} be ``noted":
 \MarkThisText[red]{% 
     \begin{align*}
         F &= ma \\
         \implies E &= mc^2
     \end{align*}
 }%
Text after \verb|align| should \emph{not} be ``noted".

Text before \verb|enumerate| should \emph{not} be ``noted":
 \MarkThisText[brown]{% 
     \begin{enumerate}
         \item List Item 1 
         \item List Item 2 
     \end{enumerate}
 }%
Text after \verb|enumerate| should \emph{not} be ``noted".
\end{document}

答案1

我会手动定位标记。

\documentclass{article}
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}

\newcommand{\DrawBrace}[3][]{%
    \begin{tikzpicture}[overlay,remember picture]
        \coordinate (Top) at 
            ($(#2.north  -| current page.south east)+(-4.5cm,0.25\baselineskip)$);
        \coordinate (Bottom) at 
            ($(#3.south -| current page.south east)+(-4.5,-0.25\baselineskip)$);
                \draw [
                    line width=1.0pt, 
                    decoration={brace, amplitude=0.30em}, 
                    decorate, #1,
                    ] (Top) -- (Bottom)
                    node[rotate=90, midway, below] {Note};
    \end{tikzpicture}%
}

\newcommand{\MarkThisText}[2][]{%
    %% conditions to determine if this text is to be suppressed omitted
    %% \iftoggle{SuppressThisText}{}{%
    \color{#1}%
            #2%
      \color{black}%
    %% } % end \iftoggle{DisplayThisText}
}%

\newcommand\startmark[1]{\tikzmark{start#1}}
\newcommand\stopmark[1]{\tikzmark{stop#1}\DrawBrace{start#1}{stop#1}}

\begin{document}
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at dignissim eros. 
 Morbi faucibus sit amet felis a accumsan.  Aliquam 
 dapibus pellentesque dui, vitae aliquam turpis semper eget.

 \MarkThisText[blue]{% 
     \startmark{a}%
     Donec egestas leo nibh, at malesuada leo congue non. 
     Cras laoreet lectus sed tortor laoreet, ac aliquet nibh condimentum. 
     \begin{align*}
         F &= ma \\
         \implies E &= mc^2
     \end{align*}
     Nam elementum ante non nunc facilisis porttitor. Nullam non suscipit lorem. 
     Sed arcu dui, accumsan et pretium dictum, venenatis id metus.%
     \stopmark{a}%
 }

 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at dignissim eros. 
 Morbi faucibus sit amet felis a accumsan.  Aliquam 
 dapibus pellentesque dui, vitae aliquam turpis semper eget.


Text before \verb|align| should \emph{not} be ``noted":
 \MarkThisText[red]{% 
     \begin{align*}
         \startmark{b}F &= ma \\
         \implies E &= mc^2\stopmark{b}%
     \end{align*}
 }%
Text after \verb|align| should \emph{not} be ``noted".

Text before \verb|enumerate| should \emph{not} be ``noted":
 \MarkThisText[brown]{%
     \begin{enumerate}
         \item \startmark{c}List Item 1 
         \item List Item 2\stopmark{c} 
     \end{enumerate}
 }%
Text after \verb

|enumerate| should \emph{not} be ``noted".
\end{document}

相关内容