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

Added ability to specify target directory when exporting #4971

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jamescormack
Copy link

@jamescormack jamescormack commented Feb 19, 2024

Hi,

Scratching an itch, I found that I wanted to export to latex to a specific folder containing my latex template assets. I didn't want to use the CWD which is what is set in the code as I wanted my markdown and output/template to be in a different folder. I made the attached changes and I'm submitting them back in case they are helpful.

Hope this is useful. I've started using Zettlr instead of Joplin and it's much better for academic writing - Thanks so much.

-James

Description

With this change you can place the output file wherever you please independently of the current working directory. When exporting a single file the target directory can be specified in the YAML frontmatter as zettlr:pandoc_target_filename (similar to how the existing zettlr:pandoc_target_dir is implemented). When exporting a project the target directory can be specified in the .ztr_directory project json as targetDir.

Changes

Changed Exporter.tx and Dir-Exporter.ts to incorporate target dir for exporter. Small change to FSAL to add target directory field.

Additional information

TODO: Add a field to the project_settings:Files tab to specify the target directory. Currently I manually add 'targetDir' to the .ztr_directory json.

Tested on: MacOS

Copy link

boring-cyborg bot commented Feb 19, 2024

Thank you for opening your first PR! 🎉 We are very happy and would like to thank you very much for your contribution. If everything checks out, we'll make sure to review the PR as soon as possible and give feedback. In the meantime, to make the reviewing process as fast as possible, you can help us by checking the following things:

  • Did you follow the JSStandard coding style? - Did you comment everywhere where the necessity of a piece of code or the
    way it was implemented is not immediately obvious?
  • Did you attempt to stick as much to current coding habits as possible?
    (Note that this does not apply to pieces of code where we ourselves
    obviously violated good coding practices, which unfortunately happens
    sometimes. But please indicate this in your PR so that we know what you
    rectified!)

Furthermore, make sure that the linter does not complain, which will check your code on every new commit. If the linter task fails, make sure to run yarn lint locally and check the file eslint_report.htm which will tell you precisely what went wrong.
Stay sharp, and thanks again!

@jamescormack jamescormack marked this pull request as ready for review February 19, 2024 06:27
@nathanlesage
Copy link
Member

First of all, thanks for your work!

Then, I have a question, because I'm a bit confused: The current version of the app already allows for a selection of the target directory in the exporter -- only the project-based export doesn't (yet). Is the latter the use-case which you wanted to address? Because the former is already addressed. I just want to make sure I fully comprehend the intention behind your PR.

@jamescormack
Copy link
Author

Hi Nathan, its probably me that's confused. You are right, my primary goal was to get the project based export to work as I'm going to be writing a large multi-chapter document. I did the per-file exporter too because I could not see how to do it otherwise. How do you specify the target dir on a per-file export?

@jamescormack
Copy link
Author

jamescormack commented Feb 21, 2024

... I probably should be clearer as to what I want to achieve...

I have a folder structure like this:

.
\latex-template-folder
\images
\1_first_chapter.md
\2_second_chapter.md
\pandoc_template.tex

I want to generate my latex file into the latex-template-folder as that contains all the style information so latex can then generate my document without having to move files around. My pandoc template stays on the top level as does my markdown and an images folder for pulling in assets.

Currently when doing an single file export in export.ts we are give a choice. We can set the target dir by selecting it from a dialog [ 'ask' ] , we can set target dir to the temp directory [ 'temp' ] or we can set the target directory to the current working directory ['cwd'].

https://github.com/Zettlr/Zettlr/blob/7bc678982ebe64607c139ac982a8ad681100be63/source/app/service-providers/commands/export.ts#L112C1-L130C6

I don't want any of those options. I wanted the exporter to pick up the target directory from the metadata in my markdown file. If there is another way to do this please let me know. I couldn't find anything in the documentation or in my brief wade through the code.

I'm aware my solution might not be the cleanest but I wanted to do it with minimal code change. Happy if you want to propose a better way to do it - I'm sure there is.

regards, J

@nathanlesage
Copy link
Member

That is definitely what the Pandoc working directory is supposed to achieve. We should work from there. If I remember correctly I put together some documentation as well, so maybe have a read and see how we can work from there.

@jamescormack
Copy link
Author

jamescormack commented Feb 21, 2024

Hi Nathan,

Looking at the code, it looks to me like export.ts sets the exporterOptions.cwd from the pandoc_working_dir value (line 109) and then, if 'cwd' is set, sets the exporterOptions.targetDirectory to the same value.

exporterOptions.cwd = fileDescriptor.frontmatter.zettlr.pandoc_working_dir

This cwd specifies where the source files are located and where pandoc looks for source images etc, correct? If 'cwd' is set as an export option it also specifies the target directory which is how the output-file for pandoc is generated.

I want to override the output folder without changing where the source files are located. i.e. I want to chang targetDir so that when the default-exporter overrides the output-file in the defaults file, it can generate a filename that is NOT in the working directory.

const target = path.join(options.targetDirectory, `${title}.${extension}`)

My understanding was that pandoc_working_dir was to specify the root folder of all input files/images etc for pandoc. Let me know if I've got it wrong. Meanwhile, I will do some further reading to see what I've misunderstood.

@jamescormack
Copy link
Author

... I'll also have a closer look at how cwd is used. Perhaps a simpler solution for me it just place the pandoc_template.tex into the latex-template folder and set the pandoc_working_dir to './latex-template'

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

Successfully merging this pull request may close these issues.

None yet

2 participants