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 a macro for importing settings from external files #77

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mozhewen
Copy link

@mozhewen mozhewen commented Sep 2, 2024

A solution to #76

After thinking about it a few days, I realized that reusing settings from former code blocks may lead to uncontrollable behavior because when those blocks are changed, some update events should be triggered for other blocks, which complicate the problem.

On the other hand, I found importing external files is easier to implement. Now we can write a %:input macro

%:input path/to/settings.tex
\begin{document}
% ...
\end{document}

to import settings from files. The result now looks like
Screenshot 2024-09-03 at 01 30 27
Screenshot 2024-09-03 at 01 30 40

It's not a perfect solution for the moment. The blocks do not respond automatically to the settings file change. But, as the
settings are not changed frequently, and one can always reopen the .md file to refresh all pictures, it's acceptable for me.

Hope someone comes up with a better idea.

@artisticat1
Copy link
Owner

Thanks for the PR! I'll try to take a look soon.

@a76854
Copy link

a76854 commented Sep 29, 2024

Great solution, but I don't know how to edit content of settings.tex. Can you give me an example? Thanks a lot.

@mozhewen
Copy link
Author

mozhewen commented Nov 6, 2024

Great solution, but I don't know how to edit content of settings.tex. Can you give me an example? Thanks a lot.

@a76854 It's basically a list of \usetikzlibrary{...} and \tikzset{...}. The usage of these commands can be found in TikZ & PGF‘s manual. In fact, you can write any tex code in some file and import it by %:input (with no indent). The macro will just be replaced by the file content.

@cdpotti
Copy link

cdpotti commented Nov 6, 2024

Great solution, but I don't know how to edit content of settings.tex. Can you give me an example? Thanks a lot.

@a76854 It's basically a list of \usetikzlibrary{...} and \tikzset{...}. The usage of these commands can be found in TikZ & PGF‘s manual. In fact, you can write any tex code in some file and import it by %:input (with no indent). The macro will just be replaced by the file content.

Dear @mozhewen ,
does this mean it's possible to use different libraries than the default ones the plugin comes with?

After creating an issue about this topic i jsut stumbled across this thread, sorry if I mistaking something here.

@mozhewen
Copy link
Author

Great solution, but I don't know how to edit content of settings.tex. Can you give me an example? Thanks a lot.

@a76854 It's basically a list of \usetikzlibrary{...} and \tikzset{...}. The usage of these commands can be found in TikZ & PGF‘s manual. In fact, you can write any tex code in some file and import it by %:input (with no indent). The macro will just be replaced by the file content.

Dear @mozhewen , does this mean it's possible to use different libraries than the default ones the plugin comes with?

After creating an issue about this topic i jsut stumbled across this thread, sorry if I mistaking something here.

@cdpotti Yes, you can use different tikz libraries documented in tikz's manual. However, I also tried some tex packages like mathtools and xcolor and they don't work (amsmath and color work fine).

async embedTexInput(tikzSource: string): Promise<string> {
return this.replaceAsync(tikzSource, /^%:input\s+(.+)$/gm, async (_, path) => {
const file = this.app.vault.getAbstractFileByPath(path);
if (file instanceof TFile) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we print a warning to the console if a user inputs a filepath that Obsidian can't locate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that would be helpful.

@artisticat1
Copy link
Owner

Hello, apologies for the delay - it looks good to me!

Can you add some documentation on this feature to the README.md?

@mozhewen mozhewen marked this pull request as draft December 7, 2024 16:03
@mozhewen mozhewen requested a review from artisticat1 December 7, 2024 16:44
@mozhewen mozhewen marked this pull request as ready for review December 7, 2024 16:45
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.

4 participants