TeX - LaTeX Asked on May 20, 2021
I’m trying to simplify my work on thesis so I create an environment for repetitive tasks. All is ok, but citing!
MWE
documentclass{article}
usepackage[romanian]{babel}
usepackage[backend=biber]{biblatex}
usepackage{csquotes}
DeclareQuoteStyle{romanian}
{quotedblbase}
{textquotedblright}
{guillemotleft}
{guillemotright}
newenvironment{qt}[1]
{begin{quote}
{enquote{{#1}}}
end{quote}
}
begin{filecontents}{jobname.bib}
@book{key,
title = {Title},
author = {Author, An},
year = {2021},
location = {Location},
publisher = {Publisher}
}
end{filecontents}
addbibresource{jobname.bib}
begin{document}
With textbackslash newenvironment:
qt
{Lorem ipsum dolor enquote{sic} amet.}
cite{key}
endqt
With normal environment:
begin{quote}
enquote{Lorem ipsum dolor enquote{sic} amet.}
cite{key}
end{quote}
printbibliography
end{document}
Output
There are a few misunderstanding of how environments work.
First off, notwithstanding that newenvironment{foo}{...}{...}
defines foo
and endfoo
doesn't mean that one can use foo
and endfoo
in the document. To the contrary, they should not.
Second problem. The command newenvironment
requires three mandatory arguments: the name of the environment, the code to be executed at the start and the code to be executed at the end. The parameter #1
in the second mandatory argument does not refer to the environment contents.
Your code
newenvironment{qt}[1]
{begin{quote}
{enquote{{#1}}}
end{quote}
}
misses the final mandatory argument and, since it's followed by a blank line, the “end part” is taken to be par
. Let's see how the call
qt
{Lorem ipsum dolor enquote{sic} amet.}
cite{key}
endqt
is processed. The macro qt
is defined to have an argument, which is found to be the braced group following. Then the “begin part” is inserted and we find
begin{quote}{enquote{{Lorem ipsum dolor enquote{sic} amet.}}}end{quote}
cite{key}
endqt
Now the code is processed normally, finding cite{key}
outside quote
. Finally par
results from endqt
.
How to fix?
documentclass{article}
usepackage[romanian]{babel}
usepackage[backend=biber]{biblatex}
usepackage{csquotes}
DeclareQuoteStyle{romanian}
{quotedblbase}
{textquotedblright}
{guillemotleft}
{guillemotright}
newenvironment{qt}[1]
{begin{quote}enquote{#1} ignorespaces}
{end{quote}}
begin{filecontents}{jobname.bib}
@book{key,
title = {Title},
author = {Author, An},
year = {2021},
location = {Location},
publisher = {Publisher}
}
end{filecontents}
addbibresource{jobname.bib}
begin{document}
With textbackslash newenvironment:
begin{qt}{Lorem ipsum dolor enquote{sic} amet.}
cite{key}
end{qt}
With normal environment:
begin{quote}
enquote{Lorem ipsum dolor enquote{sic} amet.}
cite{key}
end{quote}
printbibliography
end{document}
Correct answer by egreg on May 20, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP