模仿电子邮件回复布局:左边距有垂直线,回复除外

模仿电子邮件回复布局:左边距有垂直线,回复除外

编辑:我对我第一个较小的赏金所得到的 3 个答案不满意。所以我重写了问题以设置明确的规则和适当的赏金。


该解决方案应该创建两个环境,originalemailresponse具有以下效果:

  • -environmentoriginalemail可以包裹正常的 LaTeX 代码,其中可能包括列表、章节等,然后进行正常排版,但会稍微 ( 4pt) 缩进所有文本并在左侧添加垂直线。
  • 环境response可以在环境内部使用originalemail,导致垂直线断开,并且包含的​​文本/代码在左侧对齐,没有缩进originalemailresponse必须与左边距对齐,无论originalemail它位于 中的何处(例如,在(嵌套)itemize或内enumerate)。

概括

  • 保留原始电子邮件的布局(应该可以使用部分、列表、段落、浮点数等,就好像它是一个普通的 TeX 文档,没有回复,并且有回复和没有回复时编号应该相同)
  • \begin{document}使用这些环境后,在环境之外不需要编辑代码response。特别是,如果解决方案需要,任何enumerate或环境的暂停或恢复都应该是自动的。itemize
  • 原始布局唯一的改变是2pt在左边距显示垂直线( )并且最好有轻微的缩进(4pt)。
  • 回复和原始电子邮件的片段必须像平常一样分页。(如果您将其用于parbox回复,则不会)
  • \reply允许插入任何地方在原文中
  • 如果解决方案可嵌套,则奖励(即外部originalemail包含较旧的originalemail和响应)

规则:对于赏金,你可以自由地在现有答案的基础上进行构建,即@marmot's/Gonzalo Medina's TiZ 方法在左边距画线,@Vinccool96tcolorbox或我自己的自动暂停和恢复列表的基本方法。

Gmail 的截图大致概括了我的需求在此处输入图片描述

输入示例 这是我开始使用的文档的一个简单示例。这是一个标准的 LaTeX 文档,我将其包装到 中\begin{originalemail}...\end{originalemail}。接下来我需要在其中添加我的回复,这应该与上下文无关(即无需手动跟踪当前打开的其他环境,这就是@Vinccool96 的答案不被接受的原因)

当然,您可以编辑序言以定义新的环境。

\documentclass{article}
%you may add code here
\begin{document}
%you may add code here
    \begin{originalemail}
     %inside this, the only change I can make to the code may be within
     % \begin{response}...\end{response}
        Text text text text text text
        \section{Text text text}
            Text text
            \begin{enumerate}
                \item text 
                \begin{itemize}
                    \item text 
                    \item text 
                \end{itemize}
                \item text 
                \item text 
            \end{enumerate}
    \end{originalemail}
\end{document}

\begin{response}my response\end{response}新的环境应该允许我在里面的任何地方使用orininalemail并实现所需的布局中断。

正如@Vinccool96 所指出的,为了打破嵌套,originalemail可能需要传递一个参数\begin{response}[2]来指示应该打破的层数。但嵌套只是一个额外的好处。

答案1

\documentclass{article}

\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable}
\tcbuselibrary{skins}

\newtcolorbox{emailstart}[3][]{%
    standard jigsaw,
    opacityframe=0,
    opacityback=0,
    colback=transparent,
    grow to left by=-1.5em,
    boxrule=0pt,
    boxsep=0pt,
    breakable,
    enhanced jigsaw,
    title={On #2, #3 wrote\par},
    coltitle={black},
    attach title to upper={},
    borderline west={4pt}{0pt}{black},
    overlay unbroken and first={\draw[shorten >=1.4pt, shorten <=1.4pt] ([yshift=-1.5em]frame.north west) -- ([yshift=-1.5em]frame.north east);},
    #1,
}

\newtcolorbox{emailresume}[1][]{%
    standard jigsaw,
    opacityframe=0,
    opacityback=0,
    colback=transparent,
    grow to left by=-1.5em,
    boxrule=0pt,
    boxsep=0pt,
    breakable,
    enhanced jigsaw,
    borderline west={4pt}{0pt}{black},
    #1,
}

\newcounter{enumicounter} %counter that will save the enumeration counter

\begin{document}
    \begin{emailstart}{2019}{Einstein}
        \begin{emailstart}{2018}{Sheß}
            Text Text Text Text

            Text Text Text Text Text Text Text
        \end{emailstart}
        Here I am putting my answer text 
    \end{emailstart}
    Oh, now I see your point


    \begin{emailresume}
        \begin{emailresume}
            \section{A section}
            Some content a list
            \begin{enumerate}
                \item One
                \setcounter{enumicounter}{\value{enumi}} % save the enumeration counter
            \end{enumerate}
        \end{emailresume}
        Here even more, there's no indentation, because you closed the enumaration and the email
    \end{emailresume}
    This is an answer to your answer
    \begin{emailresume}
        \begin{emailresume}
            \begin{enumerate}
                \setcounter{enumi}{\value{enumicounter}} % continue the enumeration
                \item Two
                \setcounter{enumicounter}{\value{enumi}} %save the enumeration counter
            \end{enumerate}
        \end{emailresume}
        Answer
        \begin{emailresume}
            \begin{enumerate}
                \setcounter{enumi}{\value{enumicounter}} % continue the enumeration
                \item Three
                \item Four
                \setcounter{enumicounter}{\value{enumi}} %save the enumeration counter
            \end{enumerate}
            \section{another section}
            More Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
            \subsection{a subsection}
            More Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
        \end{emailresume}
        More
        \begin{emailresume}
            \subsection{another subsection}
            More Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text
        \end{emailresume}
        More
        \begin{emailresume}
            Bye,

            Sheß
        \end{emailresume}
        Bye,

        Einstein
    \end{emailresume}
    Bye
\end{document}

答案2

我在这里所做的只是稍微修改Gonzalo Medina 的精彩回答。当然可以再多调整一下。(我也知道这里没有什么波浪线,我太懒了,不想重命名宏。)

\documentclass{article}
\usepackage{refcount}
\usepackage{tikz}
\usetikzlibrary{calc,tikzmark}
\usepackage{lipsum}

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

\newcommand\Startsquiggly{%
  \stepcounter{tmp}%
  \tikzmarknode{a}{\strut}\label{a\thetmp}%
  \ifnum\getpagerefnumber{a\thetmp}=\getpagerefnumber{b\thetmp} \else
  \begin{tikzpicture}[overlay, remember picture]
    \draw [ultra thick,gray]
      let \p1 = (a.south), \p2 = (b), \p3 = (current page.center) in
      ( $ (\x3,\y1) + (-.55\textwidth,0) $ ) --  ( $ (\x3,\y3) + (-0.55\textwidth,-0.5\textheight) $ );
  \end{tikzpicture}%
  \fi%
}

\newcommand\Endsquiggly{%
\tikzmarknode{b}{\strut}\label{b\thetmp}
  \ifnum\getpagerefnumber{a\thetmp}=\getpagerefnumber{b\thetmp}
  \begin{tikzpicture}[overlay, remember picture]
    \draw [ultra thick,gray]
      let \p1 = (a.south), \p2 = (b), \p3 = (current page.center) in
      ( $ (\x3,\y1) + (-.55\textwidth,1em) $ ) --  ( $ (\x3,\y2) + (-.55\textwidth,1em) $ );
  \end{tikzpicture}%
  \else
  \begin{tikzpicture}[overlay, remember picture]
    \draw [ultra thick,gray]
      let \p1 = (a.south), \p2 = (b), \p3 = (current page.center) in
      ( $ (\x3,\y3) + (-.55\textwidth,.5\textheight) $ ) -- ( $ (\x3,\y2) + (-.55\textwidth,1em) $ );
  \end{tikzpicture}%
  \fi
}

\newcommand\Squ[1]{\Startsquiggly#1\Endsquiggly}
\AtBeginDocument{\Startsquiggly}
\AtEndDocument{\par\Endsquiggly}
\newcommand{\response}[1]{\par\Endsquiggly#1\par\Startsquiggly}
\begin{document}
Some text, with pictures, lists, sections
\begin{enumerate}
\item Some text, with pictures, lists, sections
\response{answer1}
\item Some text, with pictures, lists, sections
\response{answer2}
\end{enumerate}
Some text, with pictures, lists, sections
\response{this is my answer}
Some text, with pictures, lists, sections
\section{section}
\subsection{subsection1}
Some text, with pictures, lists, sections
\subsection{subsection2}
Some text, with pictures, lists, sections
\subsection{subsection3}
Some text, with pictures, lists, sections
\response{I also have an answer here}
More text
\end{document}

在此处输入图片描述

答案3

我想到了一个解决方案,但我仍然对硬编码的内容数量感到不满。例如

  • 它要求我改变\begin{enumerate}[some arguments] 一切\begin{enumerate}{some arguments}
  • 仅适用于最多固定数量的嵌套enumerate
  • 如果原始文档使用itemize或其他内容,则可能会失败。
  • 不能嵌套

因此,尽管我发布这篇文章是为了回答我自己的帖子,但我并不认为它完整,并且很乐意让任何人将其改编成更通用的版本

\documentclass{article}

\newcounter{breakdepth}
\usepackage{enumitem}
\usepackage{letltxmacro}

%redefine enumerates so that they are automatically resumable
\LetLtxMacro\ooenumerate\enumerate
\LetLtxMacro\endooenumerate\endenumerate
\makeatletter
    \renewenvironment{enumerate}[2][0]{%
        \ifx0#1%i.e. this is not a resume, but a new list, so start naming it.
            \ooenumerate[series=level\the\@enumdepth,#2]%
        \else
            \ooenumerate[#2]%
        \fi
    }{
         \endooenumerate%
    }
%define the command that breaks the \report environment, closes all enumerates, but resumes them afterwards
\newcommand{\response}[1]{%
\setcounter{breakdepth}{\the\@enumdepth}%
\ifnum\value{breakdepth}>3  \end{enumerate} \fi%
\ifnum\value{breakdepth}>2  \end{enumerate} \fi%
\ifnum\value{breakdepth}>1  \end{enumerate} \fi%
\ifnum\value{breakdepth}>0  \end{enumerate} \fi%
\end{report}%
#1%
\begin{report}%
\ifnum\value{breakdepth}>0  \begin{enumerate}[]{resume*=level\the\@enumdepth}\item[]\fi%
\ifnum\value{breakdepth}>1  \begin{enumerate}[]{resume*=level\the\@enumdepth}\item[]\fi%
\ifnum\value{breakdepth}>2  \begin{enumerate}[]{resume*=level\the\@enumdepth}\item[]\fi%
\ifnum\value{breakdepth}>3  \begin{enumerate}[]{resume*=level\the\@enumdepth}\item[]\fi%
}
\makeatother
%define the environment that has a slight indentation and a vertical line for the original text
\usepackage{mdframed}
\newenvironment{report}{\begin{mdframed}[linewidth=1pt,topline=false,rightline=false,bottomline=false,linecolor=black,innerleftmargin =0cm, leftmargin=2pt,innerrightmargin=1pt]}{\end{mdframed}}

\begin{document}
    \begin{report}
    \section{first section}
    \begin{enumerate}{label=\roman*.}
    \item ione 
    \begin{enumerate}{}
    \item aone
    %%%%%%%%%
    \response{test} 
    %%%%%%%%%
    \item atwo
    \end{enumerate}
    \item itwo
    \response{test} 
    \end{enumerate}
    \section{a section}
    Some text that is not inside a list
    \response{test} 
    more text
    \end{report}
\end{document}

在此处输入图片描述

相关内容