Hi !
I have many .txt files to fill my document. I've just discovered that read() returns a string, not a content, so I can't format anything from my txt file.
I know I should have used .typ files and used include(), I tested and it works well. But it's too late now.
Best would be a way to convert strings to contents, but I can't find anything. Any help ?
Thank you very much,
Adau
#string to contents
29 messages · Page 1 of 1 (latest)
can't you just do text(<the string>)
You can use eval
But I'd just automate .txt to .typ "conversion"
should be doable with a simple shell script
Note that just calling text with a string rarely makes sense. It is meant to be used for setting text properties like fill etc. If you just want to convert a string to content, then [#x] would be more idiomatic. The text function actually takes content, it just happens to do the job because wherever content is expected a string works, too.
I’m on windows on my wife’s computer and I don’t know a thing about powershell
It just prints the [] characters, that’s weird
eval() works, it’s odd but it works
May I advice to improve the read() documentation. I won’t be the last one using the read() function for txt files and expecting a “copy/paste” behavior .
The most idiomatic way would have been to include() typ files
You might find something relevant here https://stackoverflow.com/questions/65972645/powershell-changing-bulk-file-extensions-all-at-once
can't test any of it though as I'm on Linux
I’ll make a PR to improve the documentation
A string to content function might be useful as well
Thank!
eval does technically work like a string to content function (in the sense that it allows formatting inside the string)
unless I misunderstood
?r #type(eval("Hi", mode: "markup"))
It does work yes. But docs says only as last resort 😅
what's the problem with that?
note that Typst doesn't enforce the .typ file ending
so include "myfile.txt" should work
That’s not a problem, this is something I should have known before.
I will try include the txt files, but when I quickly tried it didn’t work. I’m not in front of the computer anymore, I’ll tell you soon
FYI, yes it works, but the LSP complain that include only works with typ files, whereas it compiles perfectly.
So I will file a PR for the LSP as well