Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add working dir / source path as template variable #5464

Closed
tstenner opened this issue Apr 24, 2019 · 5 comments
Closed

Add working dir / source path as template variable #5464

tstenner opened this issue Apr 24, 2019 · 5 comments

Comments

@tstenner
Copy link
Contributor

I've got almost the same problem as in #3431: I want to include the source file in the output document.

For context, I have included the following snippet:

$if(includesource)$
$for(sourcefile)$
\attachment[file=$sourcefile$,method=hidden] 
$endfor$
$endif$

This will include the source file as PDF attachment, but only with an absolute input file name (pandoc $PWD/test.md -t context -s -o test.pdf) or with context running from the same directory (pandoc test.md -t context -s -o test.tex; context test.tex), otherwise context will look for the file in the temporary pdf folder.

This could be solved either with a variable with the full paths (fullpathsourcefile?) or a variable with pandoc's current working directory (usable as \attachment[file=$pwd$/$sourcefile$,method=hidden]).

@tarleb
Copy link
Collaborator

tarleb commented Apr 25, 2019

As a workaround, one can set the pwd metadata field in a Lua filter:

function Meta (meta)
  -- set current working directory. Works on Mac and Linux; not sure about Windows.
  meta.pwd = os.getenv 'PWD'
  return meta
end

@agusmba
Copy link
Contributor

agusmba commented Apr 25, 2019

If 'PWD' doesn't work in windows (I haven't checked) you could use 'CD'

@tstenner
Copy link
Contributor Author

@tarleb That's an option, another idea I had was pandoc test.md -V pwd=$PWD -s -t context.

For most of my documents I have rather basic needs so panzer et al are overkill. This addition would make another common usecase doable without any addons and it complements the $sourcefile$ variable quite nicely. On the other hand, I can understand if it's found to be out of scope for plain pandoc.

@tarleb
Copy link
Collaborator

tarleb commented Apr 26, 2019

According to a StackOverflow answer, there is no easy, platform independent way to get the current working directory from within Lua. I've started work on a module to expose the relevant Haskell functions to Lua. This should also help with other common filter operations.

@mb21
Copy link
Collaborator

mb21 commented May 2, 2019

I've started work on a module to expose the relevant Haskell functions to Lua.

for reference: I guess, that's #5468

@jgm jgm closed this as completed in fee3258 May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants