3

I am using subfiles with multiple comment environments inside (which I use as translation versions and annotations of a text).

Example: guitarteacher.txt

\documentclass[../resume]{subfiles}
\begin{document}
\begin{English}
Guitar teacher.
\leavevmode
\hrulefill
\small
\begin{annotate}
\begin{itemize}
    \item Example annotation.
\end{itemize}
\normalsize
\leavevmode
\hrulefill
\end{annotate}
\end{English}

\begin{Swedish} Gitarrlärare. \leavevmode \hrulefill \small \begin{annotate} \begin{itemize} \item Example annotation. \end{itemize} \normalsize \leavevmode \hrulefill \end{annotate} \end{Swedish}

\end{document}

When I import a single sentence or word into a document with subfiles - such as:

\subfile{resume/guitarteacher.txt}

it puts in a newline afterwards, which I want to get rid of, like this:

Gitarrlärare

, Privat, 2009, etc.

Someone showed me that taking out all the whitespace inside the subfiles can take care of this problem if it's a simple file, like this:

\documentclass[./resume.txt]{subfiles}\begin{document}Some text.\end{document}

(See: Can I edit the subfiles package to not include new lines after each subfile?)

But in this case, I can't completely condense the file because then the comment environments don't work. I get error messages like "Sorry, your Latex code couldn't compile for some reason"; "Runaway argument?", "Extra }, or forgotten \endgroup", "You can't use / in vertical mode", and "Emergency stop".

There might be some way to arrange the line breaks so I don't get these errors and I don't get a newline in the output file, but that wouldn't be a good longterm solution. Instead, can subfiles be fixed so it doesn't add a newline unless there is clearly one between \begin{document} and \end{document}, or between whatever comment commands that are currently turned on, such as \begin{Swedish} and \end{Swedish}?

What would it take to fix the package? Should I edit the package myself? Is that a standard thing to do? Is it significantly difficult?

julkarham
  • 299
  • you can edit a local copy (say in the same directory as your document) but don't edit the file installed by miktex or texlive, better still is contact the maintainer (an email address is in the file) and suggest a fix to the distributed version if you think you have found a bug. – David Carlisle Sep 16 '19 at 16:37
  • 1
    Can you give a minimal working example where the use of subfiles introduces an empty line/a paragraph? Older versions may introduce an extra empty space, but I cannot reproduce a case with a new praragraph. The upcoming version of subfiles will behave like the \input regarding spaces, i.e., extra spaces will be introduced (and can be removed) in the document, not in the package. – gernot Oct 12 '19 at 10:36

1 Answers1

3

The empty lines (paragraphs) probably stem from empty lines after \end{document} in the subfile. I cannot tell for sure since the given example is not complete, but probably the unintended line breaks go away if you remove the empty lines at the end of the subfile.

Otherwise, \subfile behaves similar to \input regarding spaces (at least starting with version 1.4, 2019/10/25). This means the following.

To suppress any space between the main file and the contents of the subfile, you can either use comment signs in three places:

% main.tex
\documentclass{article}
\usepackage{subfiles}
\begin{document}
text before% <<< HERE <<<
\subfile{sub}% <<< HERE <<<
text after
\end{document}

% sub.tex
\documentclass[main]{subfiles}
\begin{document}
contents of subfile% <<< HERE <<<
\end{document}

or write everything on the same line:

% main.tex
\documentclass{article}
\usepackage{subfiles}
\begin{document}
text before\subfile{sub}text after
\end{document}

% sub.tex
\documentclass[main]{subfiles}
\begin{document}
contents of subfile\end{document}

In both cases we obtain enter image description here

gernot
  • 49,614