Is there a way to programmatically hide certain text in preview mode?

I am writing my PhD thesis in obsidian using this code to convert it to latex.

Now… in this tool, there is a way to “cancel” a certain part of the text by adding placeholders that the converter will take into account. For example:

#command_include_following_text(condition)

text here

#command_include_following_text_end

if condition is set to false, this text will not appear in the .pdf file, or in the latex version of the thesis.

Is there a way to do this in Obsidian already?

1 Like

As a Markdown you can use Markdown comment

Try this part

For example

Here's a paragraph that will be visible.

[This is a comment that will be hidden.]: # 

And here's another paragraph that's visible.

Will display as

Example of the text rendering result

Here’s a paragraph that will be visible.

And here’s another paragraph that’s visible.

Closing note

And since this is a markdown format, it should work with all markdown rendering, including Obsidian

Pandoc has --strip-comments[=true|false] which applies to html comments.

https://pandoc.org/MANUAL.html#pandocs-markdown

 

Pandoc is more versatile tool than what you would get with Obsidian plugins. You can run customized scripts in Obsidian but the framework is limited to few plugins (Templater, QuickAdd, Shell Commands, Execute Code). Templater and QuickAdd are used with JavaScript while Shell Commands and Execute Code are not limitted to one language.

Edit: also Dataview provides scripting via JavaScript

If you want to do it programmatically (i.e. show/hide based on boolean variables), an easy way would be Dataview:

`$= if (true) dv.paragraph('This will appear.')`

`$= if (false) dv.paragraph('This will NOT appear.')`

Will produce the output:

This will appear.

If you’re not actually looking for a “programming” way to do it, and just mean “How to hide certain text in preview mode”, then you are looking for comments:

https://help.obsidian.md/syntax#Comments

“Comments are only visible in Editing view”, i.e. hidden in Preview mode.

This is an %%inline%% comment.

%%
This is a block comment.

Block comments can span multiple lines.
%%
1 Like