我正在写博士论文,我需要满足关于引用的某些格式要求。我知道有这样的环境quote
。但在这种情况下,它不符合我大学的要求。我也知道有可能重新定义环境。但我不敢。
- 引文必须用斜体
- a) 如果引文超过三行,则需要缩进
b) 否则必须将其整合到正文中(基本上,三行以内的版本应该是这样的blabla bla \emph{quotation} bla bla.
:)
是否有人知道如何以包含 1. 和 2 的方式重新定义命令,那就太好了。
答案1
您可以简单地测试一下在框内设置时参数是否长于线宽的三倍。
\documentclass{article}
\makeatletter
\newcommand{\cquotation}[1]{%
% \settowidth doesn't like paragraphs
\setbox\@tempboxa\hbox{%
\def\par{\hspace{3\linewidth}}% If a paragraph is included force long form
%\let\par\space % Ignore paragraphs
#1}%
\ifdim\wd\@tempboxa>3\linewidth
\begin{quote}
\itshape
#1
\end{quote}
\else
{\itshape #1}%
\fi
}
\makeatother
\begin{document}
% Lipsum add paragraphs :-(
\def\Text{text text text text text }
\edef\Text{\Text\Text\Text\Text\Text}
\Text
\cquotation{some short quote}
\Text
\Text
\cquotation{%
Some quotation just short of three lines of text.
Some quotation just short of three lines of text.
Some quotation just short of three lines of text.
Some quotation just short of three lines of text.
Some quotation just short of three lines.
}
\Text
\Text
\cquotation{%
Some quotation shorter than three lines.
But with a paragraph inside.
}
\Text
\Text
\cquotation{%
Some quotation longer than three lines. Some quotation longer than three lines.
Some quotation longer than three lines. Some quotation longer than three lines.
Some quotation longer than three lines. Some quotation longer than three lines.
Some quotation longer than three lines. Some quotation longer than three lines.
}
\Text
\end{document}
% Lipsum add paragraphs :-(
\def\Text{text text text text text }
\edef\Text{\Text\Text\Text\Text\Text}
\Text
\cquotation{some short quote}
\Text
\Text
\cquotation{%
Some quotation just short of three lines of text.
Some quotation just short of three lines of text.
Some quotation just short of three lines of text.
Some quotation just short of three lines of text.
Some quotation just short of three lines.
}
\Text
\Text
\cquotation{%
Some quotation longer than three lines. Some quotation longer than three lines.
Some quotation longer than three lines. Some quotation longer than three lines.
Some quotation longer than three lines. Some quotation longer than three lines.
Some quotation longer than three lines. Some quotation longer than three lines.
}
\Text
\end{document}
答案2
\documentclass[a4paper]{article}
\usepackage{environ}
\makeatletter
\newenvironment{varquotation}
{\Collect@Body\varquote\ignorespaces}
{\ignorespacesafterend}
\makeatother
\newcommand{\varquote}[1]{%
\setbox0=\vbox{
\quotation\em#1\endquotation
\expandafter}%
\ifnum\prevgraf>3
\begin{quotation}\em#1\end{quotation}
\else
\emph{#1}%
\fi}
\begin{document}
Some text before the quotation
Some text before the quotation
Some text before the quotation
\varquote{This is a short quotation}
Some text before the quotation
Some text before the quotation
Some text before the quotation
\varquote{And this is a longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation}
that should be displayed.
Some text before the quotation
Some text before the quotation
\begin{varquotation}
This is a short quotation
\end{varquotation}
Some text before the quotation
Some text before the quotation
Some text before the quotation
Some text before the quotation
\begin{varquotation}
And this is a longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
longer quotation
\end{varquotation}
that should be displayed.
\end{document}
有两种形式,请选择您喜欢的一种:对于明显较短的引用,“内联”形式\varquote{text}
可能更好;无论如何,您都可以使用环境形式。您必须自定义quotation
环境以尊重其他要求。
解释。TeX 在创建段落时,会在内部参数中记录行数\prevgraf
。因此,我将引文排版在一个框中,以便计算显示时需要的行数。如果此数字大于 3,则显示引文,否则将以行内方式设置。
\expandafter
在条件语句的右括号之前使用\vbox
了刚刚建立的值\prevgraf
,因此不可能使用构建的,\box0
因为即使代码是
...
\quotation\em#1\endquotation
\global\chardef\nlines=\prevgraf}
\ifnum\nlines>3
\begin{quotation}\em#1\end{quotation}
...
“较短”的版本避免了全局分配。