1

My goal is to combine several documents into one, so maybe someone can recommend a different solution. More specifically, I need to input about 20 files in a master file, all from line 4 to the second-to-last line, inclusive (I am excluding the \documentclass tag, an \input{header} tag, and \begin and \end{document} tags).

I would like to have a command, very similar to @mpg's answer here, except where the second number is relative to the number of lines in the file. For instance, something like

\partialinput{4}{-1}{pitest}

would be great. Or maybe

\partialinput{4}{\linenumber{pitest}-1}{pitest} 

or similar (where \linenumber could be some command that gets the number of lines in the argument file). I would prefer not to use `subfiles', as that would require changing all the headers of the individual files. So, my questions are,

  1. Is there a command that gives back the number of lines in another file, or
  2. Can the \partialinput command be modified to include all but the last line in a document?

I'm not very proficient at TeX or e-TeX, so the structure of the \partialinput command is not clear to me. I initially thought that making the counter look one line ahead and stop when it reaches the end would do it, but again, I don't know enough TeX to make that happen.

4
  • I'd be tempted to generate versions of the files to partialinput using a suitable set of standard utilities such as head and tail called by write18. Or sed: tex.stackexchange.com/a/4908/28808 (this answer would be quite easy to modify)
    – Chris H
    Jun 16, 2017 at 21:31
  • why do it this way? It is far simpler just to place the bodies of the documents in separate files and then simply \input them. Jun 16, 2017 at 21:34
  • 2
    Package catchfilebetweentags might help
    – user31729
    Jun 16, 2017 at 21:53
  • @ChrisH the document may be typeset on different machines, and I'm not sure write18 will have the same result. @DavidCarlisle because I would like each of the smaller documents to be typeset separately - I suppose this is just an organizational and navigational preference. @ChristianHupfer this is what I ended up using, although I was put off by it because somewhere (can't find the question anymore) @egreg implied that catchfilebetweentags never works as expected. But it seems to work for me. Jun 17, 2017 at 21:01

0

You must log in to answer this question.

Browse other questions tagged .