2

I'm trying to define an environment which puts the text in quotation marks - however it contains a cite-command, which should not be manipulated.

Example:

\begin{myEnv}
this text in quotes. \autocite[p.123]{author.2019}
\end{myEnv}

The end-result should look like this:

"this text in quotes." (author.2019, p.123)

Currently this is the definition of myEnv:

\newenvironment{myEnv}{\grqq}{\grqq}

which looks like this:

"this text in quotes. (author.2019, p.123)"

Is there any way to 'exclude' the cite-command from being parsed?

2
  • 1
    Does an invocation of your environment always contain a text that you want to be quoted and a cite command? Commented Sep 3, 2019 at 12:06
  • @LokiRagnarok yes
    – RazorHail
    Commented Sep 3, 2019 at 12:16

3 Answers 3

1

This uses a similar approach to LokiRagnarok's answer and assumes you'll always end your myEnv environment with an \autocite (or similar; change as necessary).

enter image description here

\documentclass{article}

\usepackage{biblatex}

\newenvironment{myEnv}
  {\let\oldautocite\autocite
   \renewcommand{\autocite}{\unskip ''~\oldautocite}%
  ``\ignorespaces}
  {\par}

\addbibresource{biblatex-examples.bib}

\begin{document}

\begin{myEnv}
this text in quotes. \autocite[p.~123]{augustine}
\end{myEnv}

\begin{myEnv}
Another text in quotes. \autocite{companion}
\end{myEnv}

\printbibliography

\end{document}
1
  • This is prettier than my answer. Upvoted. (Also, TIL that renewcommand within an environment applies to that environment only, so I needn't have bothered with resetting at the end of the environment...) Commented Sep 4, 2019 at 7:30
1

You can exploit regular expressions:

\documentclass{article}
\usepackage{biblatex}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentEnvironment{myEnv}{b}
 {
  \tl_set:Nn \l__razorhall_myenv_tl { #1 }
  \regex_replace_once:nnN
   { (.*) (\s\c{autocite}.*) \Z }
   { ``\1''\c{nobreakspace}\2 }
   \l__razorhall_myenv_tl
   \begin{quote}
   \tl_use:N \l__razorhall_myenv_tl
   \end{quote}
 }{}
\ExplSyntaxOff

\addbibresource{biblatex-examples.bib}

\begin{document}

\begin{myEnv}
this text in quotes. \autocite[p.~123]{augustine}
\end{myEnv}

\begin{myEnv}
Another text in quotes. \autocite{companion}
\end{myEnv}

\printbibliography

\end{document}

enter image description here

0

Updated for the version where the environment invocation cannot be changed:

\documentclass{article}
\usepackage[ngerman]{babel} %grqq

\usepackage{xpatch}

\newenvironment{myEnv}{%
\let\oldcite\cite %save original macro
\xpretocmd{\cite}{\makebox[0em][r]{\grqq}}{}{}% 
%prepend grqq to every cite and gobble a bit of space to the left
% prepend grqq to your TEXT
\grqq}{%
\let\cite\oldcite% %switch back to old version
}

\begin{document}
\begin{myEnv}
first text in quotes. \cite[p.123]{author.2019}
\end{myEnv}

\begin{myEnv}
second text in quotes. \cite[p.123]{author.2019}
\end{myEnv}

This is a simple cite. \cite{new citation}

\begin{myEnv}
third text in quotes. \cite[p.123]{author.2019}
\end{myEnv}
\end{document}

enter image description here


General version:

Use a parameter for your environment through which you pass your citation.

\usepackage{xparse}
....
\NewDocumentEnvironment{myEnv}{ m }{%
\grqq%
}{%
\grqq #1%
}

and use it like this:

\begin{myEnv}{\autocite[p.123]{author.2019}}
this text in quotes.
\end{myEnv}

(Thanks to Phelype Oleinik for finding an error in my solution).

6
  • With \newenvironment you cannot use parameters in the \end part of the environment. You'd need to load xparse and use \NewDocumentEnvironment instead. Commented Sep 3, 2019 at 12:23
  • groan Yeah, I actually ran into this issue myself at some point and should know better. Commented Sep 3, 2019 at 12:24
  • Just one more small nitpick: the m(andatory) argument type should be enclosed in curly braces, so you'd need to use \begin{myEnv}{\autocite...}. If you provide a compilable code (which OP didn't, unfortunately), you can check if your solution works. Commented Sep 3, 2019 at 12:34
  • Fixed, thank you. Commented Sep 3, 2019 at 12:35
  • @LokiRagnarok thanks, but this does notsolve my problem because I cannot change the layout of the text. It's being auto-generated by another program. The format is always: \begin{ENVNAME}TEXT \cite[PAGE]{AUTHOR.YEAR}\end{ENVNAME}
    – RazorHail
    Commented Sep 3, 2019 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .