[Tex/LaTex] Remove unwanted vertical space before and after environment in footnote

environmentsfootnotesmemoirspacing

I am trying to make my own environment for (left-)indented blocks inside hanging footnotes, in which the normal quote environment doesn't work, it's left indent being the same as that of the indent of the footnote, so that one doesn't see it. I am now trying to do to this with the adjustwidth environment, which does the indentation as I want it, but it inserts horizontal spaces before and after the environment if there's nothing before or after it in the footnote, a behaviour which the quote environment also seems to have.

I tried to adapt the solution suggested here, but the \compress didn't seem to do anything, and the negative \vspace after the environment would pull the next line, if there was one, into last line of the environment.

\documentclass{memoir}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\setlength{\footmarkwidth}{\leftmargin}
\setlength{\footmarksep}{0em}
\footmarkstyle{#1\hfill}
\newenvironment{fnquote}[1][]{\compress\ifx\\#1\\\begin{adjustwidth}{1.5\leftmargin}{}\else\begin{adjustwidth}{1.5\leftmargin}{}[#1]\fi}{\end{adjustwidth}\vspace{-\lastskip}\vspace{-\baselineskip}\leavevmode}
\begin{document}
Some text\footnote{Enough text to be two lines in the footnote. Enough text to be two lines in the footnote. Enough text to be two lines in the footnote.
\begin{adjustwidth}{1.5\leftmargin}{}
And here we have a quote inside the footnote. With some text before or after it it looks fine, but ...
\end{adjustwidth}
Some text after the quote.
}
\footnote{
\begin{adjustwidth}{1.5\leftmargin}{}
If I have a footnote starting or ending with a quotation I get an empty line, before or after, which I don't want.
\end{adjustwidth}
}
\footnote{
\begin{fnquote}
If I have a footnote starting or ending with a quotation I get an empty line, before or after, which I don't want.
\end{fnquote}
And some more text here.
}
\footnote{Just another footnote.}
\end{document}

Is there maybe another switch I could use to trick the environment into thinking there was some text before and after it in the footnote?

Best Answer

I'm not sure this is really what you want: the result is just wrong, nobody will understand why the text in the second and third footnote is shifted right.

\documentclass{memoir}

\setlength{\footmarkwidth}{\leftmargin}
\setlength{\footmarksep}{0em}
\footmarkstyle{#1\hfill}

\newenvironment{fnquote}
 {\par
  \setbox0=\lastbox \setbox2=\hbox{\unhcopy0}%
  \ifdim\wd2>\leftmargin \nointerlineskip\else\prevdepth=\dp\strutbox\fi\box0
  \vspace{-2.83337pt plus -1.41669pt minus -0.94446pt}%
  \ifdim\wd2>\leftmargin \else\vspace{-\baselineskip}\fi
  \begin{adjustwidth}{1.5\leftmargin}{}}
 {\end{adjustwidth}\vspace{-2.83337pt plus -1.41669pt minus -0.94446pt}}
\newenvironment{fnquote*}
 {\fnquote}{\endfnquote\vspace{-\baselineskip}}

\begin{document}
Some text\footnote{%
  Enough text to be two lines in the footnote. Enough text to be two 
  lines in the footnote. Enough text to be two lines in the footnote.
  \begin{fnquote}
    And here we have a quote inside the footnote. With some text before or after
    it it looks fine, but ...
  \end{fnquote}
  Some text after the quote.}
\footnote{%
  \begin{fnquote*}
  If I have a footnote starting or ending with a quotation I get an empty line,
  before or after, which I don't want.
  \end{fnquote*}
}
\footnote{%
  \begin{fnquote}
  If I have a footnote starting or ending with a quotation I get an empty line,
  before or after, which I don't want.
  \end{fnquote}
  And some more text here.
}
\footnote{Just another footnote.}
\end{document}

The problem is that any footnote has two implicit struts at the beginning and end; when fnquote appears at the beginning, it does a \par and so the strut forms a paragraph by itself. Similarly, if no text follows fnquote, the final strut makes a paragraph by itself.

I measure the last typeset line and if it is longer than \leftmargin, it means it has text; otherwise I back up what's necessary.

For quotes ending the footnote, it's necessary to use a different environment fnquote* that backs up by a baselineskip.

enter image description here