![更新 4](https://linux22.com/image/354600/%E6%9B%B4%E6%96%B0%204.png)
我正在寻找一种方法来自动将引号与句号和逗号重叠,如下面示例图的最后两行所示。到目前为止,我发现的方法都是通过宏来实现的;我希望完全自动地完成此操作,而不在\begin
和中添加任何内容\end
{document}
,并且理想情况下还可以处理自动生成的文本,例如参考书目。
有这个软件包吗?或者有办法在普通的 LaTeX 宏中实现愚蠢的查找/替换功能吗?
\documentclass{minimal}
\begin{document}
``quoted.''
``quoted''.
``quoted\rlap{.}''
``quoted\rlap{''}.
\end{document}
更新 4
现在我找到了一种不依赖任何任意长度的方法。句号/逗号和引号完全重叠,构造后的空格似乎与引号后的空格相同(双引号或单引号)。
下一个参考书目字段的首字母大写,无需添加另一个句点\nopunct\printunit{\bibsentence}
。对我来说,这是一种反复试验的黑魔法,但到目前为止,它对我的目的有效。
\documentclass{article}
\usepackage[american]{babel}
\usepackage[autostyle=true,autopunct=true]{csquotes}
\usepackage{biblatex}
\addbibresource{example.bib}
\begin{filecontents}{example.bib}
@incollection{smith:title,
title = {The Title of the Part},
author = {Smith, John},
year = {2017},
booktitle = {The Containing Book},
publisher = {Some Publisher},
}
\end{filecontents}
\makeatletter
\DeclareQuotePunctuation{.,}
\DeclareAutoPunct{,.}
\DeclareFieldFormat%
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]%
{title}{\textquote{#1}.\nopunct\printunit{\bibsentence}\addspace}
\renewcommand*{\mktextquote}[6]{#1#2#4{%
\ifx#5.%
\ifpunct{}{\rlap{#5}}%
\else%
\ifx#5,%
\ifpunct{}{\rlap{#5}}%
\else%
\fi%
\fi%
}#3#6%
}
\makeatother
\begin{document}
here are the \verb+\textquote+'s
``Hello. A kerning test.
``Hello'' A kerning test.
\textquote{Hello}. A kerning test.
\textquote{Hello.} A kerning test.
``Hello, A kerning test.
``Hello'' A kerning test.
\textquote{Hello}, A kerning test.
\textquote{Hello,} A kerning test.
\textcite{smith:title} is saying \textquote{a thing}.
\printbibliography
\end{document}
更新 3
我离目标越来越近了。到目前为止,我发现的唯一警告是,\textquote{}
对于普通文本,您需要使用 而不是 `` 。感叹号等现在似乎可以正常工作。
\documentclass{article}
\usepackage[american]{babel}
\usepackage[autostyle=true,autopunct=true]{csquotes}
\usepackage{biblatex}
\addbibresource{example.bib}
\begin{filecontents}{example.bib}
@incollection{smith:title,
title = {The Title of the Part},
author = {Smith, John},
year = {2017},
booktitle = {The Containing Book},
publisher = {Some Publisher},
}
\end{filecontents}
\makeatletter
\DeclareQuotePunctuation{.,}
\DeclareAutoPunct{,.}
\DeclareFieldFormat
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]
{title}{\textquote{#1}.\nopunct}
\renewcommand{\mktextquote}[6]{#1#2#4{%
\ifx#5.%
\ifpunct{}{\rlap{#5}}%
\else%
\ifx#5,%
\ifpunct{}{\rlap{#5}}%
\else%
\fi%
\fi%
}#3#6%
}
\makeatother
\begin{document}
here are the \verb+\textquote+'s
``Hello. A kerning test.
``Hello'' A kerning test.
\textquote{Hello}. A kerning test.
\textquote{Hello.} A kerning test.
``Hello, A kerning test.
``Hello'' A kerning test.
\textquote{Hello}, A kerning test.
\textquote{Hello,} A kerning test.
\textcite{smith:title} is saying \textquote{a thing}.
\printbibliography
\end{document}
更新 2
我对此取得了一些进展,尽管它与\adddot
在第 153 行定义的和类似的命令有一些奇怪的错误biblatex.def
。
\documentclass{article}
\usepackage[brazilian]{babel}
\usepackage[autostyle=true,autopunct=true]{csquotes}
\usepackage{biblatex}
\addbibresource{example.bib}
\begin{filecontents}{example.bib}
@inbook{smith2017,
title = {The Title of the Part},
author = {Smith, John},
booktitle = {The Containing Book},
}
\end{filecontents}
\makeatletter
% original definition of textquote from csquotes, applied to enquote as well
\renewrobustcmd*{\enquote}{%
\@ifstar
{\csq@getcargs{\csq@tquote{}{}{\csq@iqopen@i}}}
{\csq@getcargs{\csq@tquote{}{}{\csq@oqopen@i}}}}
% from biblatex.sty but replaced enquote with textquote
\renewrobustcmd*{\mkbibquote}{\textquote}
\protected\def\blx@imc@mkbibquote{%
\blx@ifuspunct\blx@usquote\textquote}
\newcommand\EatDot[2]{}
\DeclareFieldFormat[inbook]{title}{\textquote{#1}.\printunit{\space}}
\uspunctuation
\DeclareAutoPunct{.,}
\DeclareQuotePunctuation{.,}
\renewcommand{\mktextquote}[6]{#1#2#4{%
\ifx#5.%
\rlap{#5}%
\else%
\ifx#5,%
\rlap{#5}%
\else%
\fi%
\fi%
}#3#6%
}
\makeatother
\begin{document}
here are the \verb+\textquote+'s
``Hello. A kerning test.
``Hello'' A kerning test.
\textquote{Hello}. A kerning test.
\textquote{Hello.} A kerning test.
``Hello, A kerning test.
``Hello'' A kerning test.
\textquote{Hello}, A kerning test.
\textquote{Hello,} A kerning test.
\textcite{smith2017} is saying \textquote{a thing}.
\printbibliography
here are the \verb+\enquote+'s
``Hello. A kerning test.
``Hello'' A kerning test.
\enquote{Hello}. A kerning test.
\enquote{Hello.} A kerning test.
``Hello, A kerning test.
``Hello'' A kerning test.
\enquote{Hello}, A kerning test.
\enquote{Hello,} A kerning test.
\end{document}
更新 1
除了单引号上的一些令人困惑的间距错误,以及下面示例图片中的第 4 行和第 8 行不起作用之外,我越来越接近了。棘手的部分是双引号,因为它由三个字符而不是两个字符组成,因此\@ifnextchar
毫无用处(?)。
\documentclass{minimal}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\makeatletter
\let\normalperiod=.%
\catcode`\.=\active
\let\normalcomma=,%
\catcode`\,=\active
\let\normalquote='%
\catcode`\'=\active
\let\tqdr=\textquotedblright%
\def.{\@ifnextchar'{\rlap{\normalperiod{}}}{\normalperiod{}}}
\def,{\@ifnextchar'{\rlap{\normalcomma{}}}{\normalcomma{}}}
\def¶#1{}% removes the character following it, useful to remove the extraneous
% single quote after the double quote gets substituted
\def'{%
\@ifnextchar.{%
\rlap{\textquoteright{}}%
} {%
\@ifnextchar,{%
\rlap{\textquoteright{}}%
} {%
\@ifnextchar'{%
\textquotedblright{}¶%
} {%
\textquoteright{}%
}%
}%
}%
}%
\makeatother
\begin{document}
`This is a quote.' and this is some text
`This is a quote'. and this is some text
``This is a quote.'' and this is some text
``This is a quote''. and this is some text
`This is a quote,' and this is some text
`This is a quote', and this is some text
``This is a quote,'' and this is some text
``This is a quote'', and this is some text
`This is a quote?' and this is some text
`This is a quote'? and this is some text
``This is a quote?'' and this is some text
``This is a quote''? and this is some text
``This is a quote'' and this is some text
`This is a quote' and this is some text
\end{document}
答案1
以下示例适用于 LuaLaTeX(TeXlive 2016 中的 0.95 版本):
\documentclass{minimal}
\directlua{
fonts.handlers.otf.addfeature {
name = "kern1",
{
type = "pair",
data = {
[0x002E] = {
[0x201D] = { false, { -45, 0, -45, 0 } },
[0x2019] = { false, { -45, 0, -45, 0 } },
},
}
}
}
}
\usepackage{fontspec}
\setmainfont{Latin Modern Roman}[Ligatures=TeX,RawFeature=+kern1]
\begin{document}
``quoted.''
`quoted.'
\end{document}
它基于这个问题并在句号和结束引号之间添加一些负字距。我不知道是否可以使用一些相对尺寸,例如字符的宽度,因此通过反复试验选择了 -45。结果如下所示:
答案2
如果您已更新luaotfload
(至 2.8 版本),这将提供所需的结果:
\documentclass{article}
\usepackage{fontspec}
\directlua
{
fonts.handlers.otf.addfeature
{
name = "pkrn",
type = "kern",
data =
{
["comma"] = { ["quotedblright"] = -250 , ["quoteright"] = -250 },
["period"] = { ["quotedblright"] = -100 , ["quoteright"] = -100 },
},
}
}
\setmainfont{Latin Modern Roman}[
RawFeature={+pkrn}]
\begin{document}
“quoted,” “quoted.” ‘quoted,’ ‘quoted.’
\end{document}
在standalone
课堂上,或许在其他课堂上,除非你添加,否则这将产生错误\RequirePackage{luatex85}
。
答案3
警告通知:请自行承担风险使用,它可能会破坏
csquotes
软件包中其他潜在的良好功能,并且我认为引号后的间距可能会出现问题...
\documentclass{article}
\usepackage[english]{babel}
\usepackage[autostyle=true,autopunct=true]{csquotes}
\DeclareAutoPunct{.,}
% {<qopen>}{<text>}{<qclose>}{<punct>}{<apunct>}{<cite>}
\renewcommand{\mktextquote}[6]{#1#2#4#5%
\if#5.
\kern-0.75em%
\fi%
\if#5,
\kern-0.65em%
\fi%
#3#6}
\begin{document}
\textquote{quoted} normal text
\textquote{quoted}, next sentance
\textquote{quoted}. Next sentance
\end{document}