1

I would like that a new environment of quotation/quote detect how many lines a text has, then will increase or decrease the quotation length/margin.

For example:

\newenvironment{citacao}[1]%
  {\list{}
    % if a quotation has less than 3 lines, it will be set to 1.cm
    \ifthenelse{\equal{\citacao}{true}}
    {%
        \setlength{\citacao}{1.8cm}
    }
    % if a quotation has more than 3 lines, it will be set to 4cm
    {% else
        \setlength{\citacao}{4cm}
    }
  }%
  {\endlist}

If a new environment detects that a quotation has more than 3 lines, it will set the text to 4cm, if not, the text will be set to 1.8cm. Similar to:

\newenvironment{citacao}[1]%
  {\list{}{\leftmargin=1.8cm\rightmargin=1.8cm}\item[]}%
  {\endlist}

\newenvironment{citacao}[1]%
  {\list{}{\leftmargin=4cm\rightmargin=4cm}\item[]}%
  {\endlist}

I also would like to add the selection of a language for hyphenation like:

\newenvironment{citacao}[1][english]%
  {\list{}{\leftmargin=1.8cm\rightmargin=1.8cm}\item[]}%
  {\endlist}

I tried to code like:

\newenvironment{citacao}[2]%
  {\selectotherlanguage[#1]\list{}
    % if a quotation has less than 3 lines, it will be set to 1.cm
    \ifthenelse{\equal{\citacao}{true}}
    {%
        \setlength{\citacao}{1.8cm}
    }
    % if a quotation has more than 3 lines, it will be set to 4cm
    {% else
        \setlength{\citacao}{4cm}
    }
  }%
  {\endlist}

Observe that I use XeLaTeX and the package csquotes.

  • 2
    More than three lines under what line width? – egreg Nov 22 '18 at 23:47
  • It is under 4cm. – Gustavo Reis Nov 22 '18 at 23:49
  • You want to automate modified abnt rules and make them look more rational. This is where good sense flies out of the window. – Joseph Nov 23 '18 at 0:28
  • @Joseph, actually, I use memoir instead of abntex2, because I want to have much freedom to customise. I am using @gcedo'sThesis Polimi. The problem is that in his thesis, he used caption and titlesec which are not good for the class memoir. As I use XeLaTeX, epstopdf that he used in his package is not good for XeLaTeX. I have to look for the alternatives, to make them functional with babel, memoir and XeLaTeX. I also use biblatex-abnt because I hate bibtex and natbib. – Gustavo Reis Nov 23 '18 at 1:50
  • Do you really have to follow abnt rules? Just asking, because if you do, your "customization" makes no sense. – Joseph Nov 23 '18 at 8:49
2

If your quotations are single paragraphs, this will work: the idea is to typeset the paragraph with the wide margins and use \prevgraf to know the number of lines. If the number is greater than 3, the margin is reduced when calling \list.

The same idea could be used for multiparagraph quotations, with some complications.

\documentclass{article}
\usepackage[latin,english]{babel}
\usepackage{fontspec}
\usepackage{environ}

\newlength{\citacaoindent}
\setlength{\citacaoindent}{4cm}

\NewEnviron{citacao}[1][english]{%
  \csname otherlanguage*\endcsname{#1}%
  \setbox0=\vbox{
    \hsize=\dimexpr\hsize-2\citacaoindent\relax
    \BODY\par\expandafter
  }\expandafter\ifnum\the\prevgraf>3 \setlength{\citacaoindent}{1.8cm}\fi
  \list{}{\leftmargin=\citacaoindent \rightmargin=\citacaoindent}
  \item[]\BODY
  \endlist
}

\begin{document}

\begin{citacao}
This is a short quotation in \languagename,
typeset with a wide margin.
\end{citacao}

\begin{citacao}
This is a long quotation in \languagename, that should be
typeset with a narrower margin
because it fills more than three lines
because it fills more than three lines
because it fills more than three lines
because it fills more than three lines.
\end{citacao}

\begin{citacao}[latin]
This is a short quotation in \languagename,
typeset with a wide margin.
\end{citacao}

\begin{citacao}[latin]
This is a long quotation in \languagename, that should be
typeset with a narrower margin
because it fills more than three lines
because it fills more than three lines
because it fills more than three lines
because it fills more than three lines.
\end{citacao}

\end{document}

enter image description here

  • Sorry for having forgotten that I use babel instead of polyglossia. Do setmainlanguage and setotherlanguage work babel? – Gustavo Reis Nov 23 '18 at 0:18
  • @GustavoReis No, but the code works the same if you remove the polyglossia settings and do \usepackage[latin,english]{babel}. I changed the code. – egreg Nov 23 '18 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.