I've got a LaTeX document that's build from many smaller files. When I'm editing text or formulas I usually look for some characteristic text and do something like:

find -name "*.tex" > t
grep -n 'text of interest' `cat t` | tee v
vim -q v

I see that there's a currfile package. I'd like to know if there's a way that I could use the \currfilename command in that package to stamp the margin with the filename (and/or path), or perhaps even just to generate a footnote.

EDIT: I found a way to do this in a standalone example, and that's posted below as a self-answer, which I initially thought to be sufficient. However, that answer used fancyhdr, and I'm using the classicthesis template which uses scrpage2, so a fancyhdr solution doesn't work. I've been able to make updates to classicthesis.sty to show the filenames in the chapter and section headers using \currfilepath, but would really like this to be a page level footer (one that I'd eventually make conditional on the drafting flag).

This is the scrpage2 section from classicthesis that I'd like to modify:

% ********************************************************************
% headlines
% ********************************************************************
  \RequirePackage{scrpage2} % provides headers and footers (KOMA Script)
%    \DeclareRobustCommand{\fixBothHeadlines}[2]{} % <--- ToDo
    % hack to get the content headlines right (thanks, Lorenzo!)
  • Are you adding the files using pdfpages?
    – Werner
    May 24 '12 at 23:40
  • just a main .tex file that does various \input's and \include's of other .tex files. May 24 '12 at 23:41
  • 1
    While this does not answer your question you should really consider using the --synctex compile time option that is built into most of the editors. You simply right click on the output PDF and the actual source file that produced it opened. This will save you a lot of time. May 25 '12 at 0:06
  • Looks like I have to use TexWorks instead of acrobat to view the pdf for this to work. Thanks for the tip. It would be nice to be able to invoke other editors though. Do you know of a way to do that? May 25 '12 at 1:53
  • 1
    My LaTeX environment (Windows) is the Sublime Text 2 editor with the LaTeXTools package which allows a forward and inverse search with the SumatraPDF viewer.
    – schlamar
    May 25 '12 at 7:35

It's perhaps poor form to answer my own question, but I found a mechanism for this in the following question:

Add logo on each page.

The following example shows how things fit together


where f1, f2, f3, ... all contain the following


As desired, I see a/b/f1.tex, a/b/f2.tex on all the \include generated pages (and the main .tex filename on the one that does the \include's).

  • It's perfectly acceptable to answer your own question – it might be a valuable source for others! You should also consider accepting it, eventually (maybe after waiting a couple of days for other answers.)
    – Daniel
    May 25 '12 at 10:39
  • With currfile there should not be a reason to use \clearpage at the end of \include file. \include adds a \clearpage before and after the file content anyway and currfile uses filehook to change the file names after the last page is written. Did you experienced that differently? I'm the author of currfile and filehook so I would like to know if there are any issues. Originally I had similar code in my svn-multi package which required such an explicit \clearpage to get the header and footer of the last pages correct.
    – Martin Scharrer
    May 26 '12 at 10:09
  • You are right. \clearpage is not required with any of the \include'd files. May 26 '12 at 13:53

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.