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

Path to include code file differs depending on output format e.g. HTML or PDF #4

Open
MichelDSchmid opened this issue Feb 15, 2023 · 3 comments

Comments

@MichelDSchmid
Copy link

I figures out some more details and according to your request from here quarto-dev/quarto-cli#4340 (comment) I will open this issue:

To get code highlighting in HTML AND PDF I have to include the code file with different path:
`
::: {.content-visible when-format="html"}
```{.c include="../code/test.c"}
```
:::

::: {.content-visible when-format="pdf"}
```{.c include="./code/test.c"}
```
:::
`
On this way I get the code highlighting in html and pdf.
I attached the complete test project.
GBSSG_Skripte_030_Physik.zip

Quarto Version: 1.2.334 with installed include-code-files extension.

Thank you very much for your help
regards
Mike

@drriguz
Copy link

drriguz commented Mar 11, 2023

I found the same issue when rendering HTML and MS.
I have to hard code the absolute path in include-code-filters.lua in order to make it work in both formats:

local function transclude (cb)
  if cb.attributes.include then
    local path = "C:/Users/dr/Desktop/mybook/code"..cb.attributes.include
    local fh, err = io.open(path)

Can we get the project root path? I did not find any kind of api or environment variables.

@allefeld
Copy link

Can we get the project root path? I did not find any kind of api or environment variables.

I just searched for that myself, and as far as I can tell, this is not exposed by Quarto.

@cderv
Copy link
Contributor

cderv commented Mar 11, 2024

There is quarto.project.directory

This is still something we need to document

It was only mentioned in Changelog for 1.2
https://github.com/quarto-dev/quarto-cli/blob/4b0bbb9709044ff26deb3833a06aa99dc69836f2/news/changelog-1.2.md?plain=1#L31-L38

You could use that to tweak the lua extension code

    local fh = io.open(pandoc.path.join({quarto.project.directory, cb.attributes.include}))

This will work only in Project. We need to probably go to the root issue here in Quarto CLI:

Lua code working directory (pandoc.system.get_working_directory()) is not the same for HTML and PDF rendering...
This is unexpected to me. 🤔

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