TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Assume the file, source.tex is placed in /home/user/Birds/ and the user types context source.tex to compile the file. Is there a way for ConTeXt to retrieve the name of the folder that the file is located in (in this example, "Birds"), for use as a variable? This might be used, for example, to give the document a title, e.g. \title{\directoryname}.

  • This will only be used on a Linux system and needn't be compatible with other systems.
  • Directory names with spaces might appear, e.g. /home/user/Tropical\ Fish/.
share|improve this question
  \cldcontext {lfs.currentdir ()}
share|improve this answer

In ConTeXt:



share|improve this answer
I'm assuming this is specific to the LuaTeX engine? – Sean Allred Feb 23 '14 at 18:49
The question is tagged "context-mkiv," so yes, this is luatex. – Thomas Feb 23 '14 at 21:05
Ah; I'm not terribly familiar with either ConTeXt or LuaTeX, but I understood ConTeXt to be just a format—didn't know MkIV was LuaTeX-specific :) – Sean Allred Feb 23 '14 at 23:15
@Sean Allred: If you’re curious about Context’s Lua integration, I can recommend mk.pdf, hybrid.pdf and the lists status-files.pdf as well as status-lua.pdf. – Philipp Gesang Feb 24 '14 at 18:27

The \SetMacroToShellOutput defined below will set the given csname to the ouptut of the shell command that is provided to it. So


will set \DirectoryNameWithPath to the full Unix path of the current file name. You can use any Unix comamnds other than pwd and get the desired result. For instance

    \SetMacroToShellOutput{\FileNameWithoutPath}{basename `pwd`}

will set \FileNameWithoutPath to the current file name (without the path).




      \@@input|"#2" }}%

DirectoryNameWithPath = \DirectoryNameWithPath
share|improve this answer
Or like in Context, Latex users can just use Luatex: \directlua {tex.sprint (lfs.currentdir())}. – Philipp Gesang Feb 23 '14 at 10:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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