如何在行前添加“>”?

如何在行前添加“>”?

为了回答某个场地的同行评审员,一种方法是创建一个 TeX 文件,在其中引用评论,方法是在行前添加“>”,然后用简单的行回答您的编辑。

手动将“>”符号放在每行的开头并不容易,而且行不会对齐,因为您必须手动转到下一行的开头。

是否有任何自动的方法可以将“>”符号放在段落整行的开头?

答案1

enter image description here

\documentclass{article}
\setlength\parindent{0pt}
\setlength\parskip{\baselineskip}

\newenvironment{q}
{\bigskip
\hspace*{1em}\begin{minipage}[b]{\dimexpr\textwidth-1em}}
{\par
 \count0=\prevgraf
 \count2=\prevgraf
 \vskip-\baselineskip
 \loop
 \llap{\textgreater\space}\par
 \vskip-2\baselineskip
 \advance\count0 -1
 \ifnum\count0>0
 \repeat
 \kern\count2\baselineskip\mbox{}%
 \end{minipage}}




\begin{document}

\begin{q}One two three four \def\z{Red blue elephant giraffe green yellow monkey dog cat purple}
\z. \z\ \z. Five six seven \z.
\end{q}
Some comment on the quoted text


\end{document}

答案2

ConTeXt 用户可以使用delimitedtext用于引用和块引用的环境。nextleft您可以使用它来设置显示在每行左边距的符号。

\definedelimitedtext
    [thread]
    [location=paragraph,
%    indenting=no,
     left={> },
     nextleft={> }]

\setupindenting[yes,big]

\starttext

\input ward

\startthread
\input ward\par
\input ward
\stopthread

\input ward

\stoptext

这种方法的局限性在于您必须禁用段落的缩进,因为第一行中的符号将被放置在错误的位置。

Repeated symbol at the left margin with the delimited text mechanism.

虽然可以在段落不超过一个的情况下修复第一行的问题,但借助机制可以找到更好的解决方案linenumbering。行号计数器可以通过设置隐藏conversion=empty

\definelinenumbering
    [thread]
    [conversion=empty,
     location=text,
     margin=\widthofstring{> },
     left={> }]

\setupindenting[yes,big]

\starttext

\input ward

\startlinenumbering[thread]
\input ward\par
\input ward
\stoplinenumbering

\input ward

\stoptext

Repeated symbol at the left margin with the line numbering mechanism.

答案3

以下解决方案也适用于跨页面,但仍然需要一点运气:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lipsum}

\makeatletter

\newenvironment*{threadstylequote}{%
  \par
  \dimen@ \prevdepth
  \setbox\z@ \vbox\bgroup
    \prevdepth \dimen@
    \sbox\z@{\textgreater\ }%
    \leftskip \wd\z@ \relax
    % A legal breakpoint must exist between any two lines of a paragraph:
    \ifnum\interlinepenalty<\@M\else
      \interlinepenalty 9999
    \fi
    \ifnum\clubpenalty<\@M\else
      \clubpenalty 9999
    \fi
    \ifnum\widowpenalty<\@M\else
      \widowpenalty 9999
    \fi
    % Also ensure that e-TeX extensions are not used (standard LaTeX does not 
    % use them):
    \interlinepenalties \z@
    \clubpenalties \z@
    \widowpenalties \z@
}{%
    \par
  \egroup % finish \vbox
  \splitmaxdepth \maxdepth % to be safe
  \splittopskip \z@skip
  \vfuzz \maxdimen % suppress overfull \vbox warnings
  \savingvdiscards \@ne
  \loop
    \setbox\tw@ \vsplit\z@ to\z@
    \unvbox\tw@
    \setbox\tw@ \lastbox
    \nointerlineskip
    \ifhbox\tw@
      \hbox{\rlap{\textgreater\ }\box\tw@}
    \else \ifvbox\tw@ % this should never happen...
      \box\tw@ % ... but if it does, simply reinsert the box
    \fi\fi
  \unless\ifvoid\z@
    \splitdiscards
  \repeat
}

\makeatother

\tracingpages = 1 % You can check in the log file that the club line at the end 
                  % of page 1 has been assessed at the usual penalty.

\begin{document}
\lipsum[1]
Text with some descenders: fgjpqy.
\begin{threadstylequote}
    \lipsum[2-7]
\end{threadstylequote}
\lipsum[8]
\end{document}

输出:

Output from the code

相关内容