3

I have a package of my own loaded when a certain option is passed to a class of my own (based in turn on the memoir class). The package is devised for typesetting letters. Except for the body of the letter itself, everything is defined in the class, in the package, and in the document's preamble -- in the latter, it is in terms of key=value syntax. I have the following code in the package:

\AtBeginDocument{%%
    \pagestyle{UVLetterHdrs}% Page headers 
    \putUVHeading% Just a macro to type some preliminary stuff
    \vspace*{3\baselineskip}\par\noindent%
    Salutation,\ignorespaces% A literal string (no unwanted space appears here) 
    \par\vspace*{\baselineskip}\noindent\ignorespaces\relax%%
}%%

% From atbeginend package
\BeforeBegin{document}{\ignorespaces\relax}% A couple of desperate attempts
\AfterBegin{document}{\ignorespaces\relax}%

Then, in the document's file, after setting the corresponding keys, I have the lines

\begin{document} 
% The problem appears here but it disappears if I add "%" 
% right after the environment's starting command.
Text of the letter.
\end{document}

My issue is that, while I don't have any unwanted horizontal space before the starting line Salutation,, there is a small horizontal space before Text of the letter. This space is removed if I type a comment mark % immediately after \begin{document}.

I have tried everything that has come to my mind regarding possible spurious spaces: I have ended each and every line (literally all of them) in the class and the package files with % (which is why you can see double percentage marks in the above code excerpts), and I've tried using \ignorespaces and \relaxes beyond reason, as you may see there, too. Besides, the space appears not before the "salutation" line, but right after whatever it is that follows the \begin{document}, so the problem seems to be located in that code area.

I'm sorry I cannot provide an MWE; the class and the package codes are too long for that. I understand that this is a big hindrance, but if somebody comes up at least with some idea of what may be going on, that'd be much appreciated.

EDIT:

After the comments and the answer by lockstep, I tried moving the code from \AtBeginDocument to the environment's body; that is to say, after the preamble, my document's master .tex file reads:

\begin{document}
\pagestyle{UVLetterHdrs}
\putUVHeading
\vspace*{3\baselineskip}\par\noindent
Salutation,
\par\vspace*{\baselineskip}\noindent 
Text of the letter.
\end{document}

The unwanted space dissapeared and everything worked fine. I have also started the contents of this environment with the literal string Salutation, and the space appeared there. By the way, this is not an indentation space. The problem is definitely related with the \AtBeginDocument command, but I haven't been able to find out what it is about. Any suggestions would be welcome.

closed as unclear what you're asking by egreg, Gonzalo Medina, Fran, user31729, user13907 Feb 19 '15 at 21:06

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    the horizontal space is almost certainly the paragraph indentation. notice that within the \AtBeginDocument there are two instances of \noindent, to avoid having the salutation spaced over to the right. you can precede your first sentence by \noindent, or if you want no indentation anywhere in the document, you can \setlength{\parindent}{0pt} in the preamble. in that case you should also use vertical space between paragraphs; the easiest way to do this is to use the parskip package. – barbara beeton Aug 10 '13 at 12:15
  • @barbarabeeton: I'm afraid it is not the paragraph indentation. It is a small space, close to 0.5 em in the \normalfont and \normalsize, only maybe a bit larger. The document's \parindent is larger than that space. I appreciate your suggestion, though, given I've got no MWE to offer for guidance. I thought that maybe the indentation in my code could make for a reason, but since I've got each and every end of line commented, I understand that's not it. – Marcos Aug 10 '13 at 19:05
  • 4
    okay, looking more closely at the code you included, i see there's a \relax after \ignorespaces in several places. that's one place where you definitely do not wans \relax -- it nullifies the action of \ignorespaces. try getting rid of it, and see what you get. since you say the space is about .5em, that's close to a word space, so it's the "right size". – barbara beeton Aug 10 '13 at 19:11
  • @barbarabeeton: I've just done so, but the space remains. Is it still possible, after having all the lines commented right after the last "non-white" character in each one, that some unwanted space is "creeping in" from my class or my package code? Let me stress again that a % mark right after \begin{document} removes the unwanted space -- though a way out, this is not a satisfying solution, of course. – Marcos Aug 10 '13 at 19:27
  • \@afterindentfalse\@afterheading is macro that suppress indentation. So I think @barbarabeeton is right. Have you tried \setlength{\parindent}{0pt} to see if the space had gone? – Francis Aug 10 '13 at 20:22
4

Perhaps adding \@afterindentfalse\@afterheading at the end of \AtBeginDocument helps in your case? (This is borrowed from cgnieder's answer to Reliable code for automatic \noindent after specific environments?)

\documentclass{article}

\makeatletter
\AtBeginDocument{%
    \vspace*{3\baselineskip}\par\noindent
    Salutation,%
    \par\vspace{\baselineskip}\@afterindentfalse\@afterheading
}
\makeatother

\usepackage{lipsum}

\begin{document}

\lipsum[1]

\end{document}

enter image description here

  • This made it. Just in order to not let this remain in the dark, any idea about the possible reason behind this unwanted space? – Marcos Aug 10 '13 at 19:56
  • @Marcos Sadly, no. – lockstep Aug 10 '13 at 19:57
  • I have edited my OP. Does the extra information I've appended help in suggesting some idea about what's going on? – Marcos Aug 11 '13 at 22:33
0

Try replacing

Salutation,\ignorespaces% A literal string (no unwanted space appears here) 
    \par\vspace*{\baselineskip}\noindent\ignorespaces\relax%%

with

Salutation\\[\baselineskip]

That will give a blank line after Salutation without interrupting the current paragraph, and should ignore any following white space.

Another possibility is that you need \ignorespacesafterend somewhere, to ignore spaces after an environment, which is not the same thing as ignoring spaces after the last macro inside the envvironment. But without a complete MWE, that's a guess.

I recommend you take time out to remove all your failed attempts to fix this from your code. They are only adding obfuscation, and as barbara beeton said, some are self-contradictory.

  • Welcome to TeX.SX! In most cases it is better so provide a full example in order to show that the answer is a solution – user31729 Feb 19 '15 at 18:55

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