#string to contents

29 messages · Page 1 of 1 (latest)

rancid lark
#

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

astral egret
#

can't you just do text(<the string>)

timid dew
#

You can use eval

astral egret
#

ah

#

yes sorry, I misunderstood

timid dew
#

But I'd just automate .txt to .typ "conversion"

#

should be doable with a simple shell script

potent copper
# astral egret can't you just do text(<the string>)

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.

rancid lark
rancid lark
#

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

rancid lark
#

I’ll make a PR to improve the documentation

#

A string to content function might be useful as well

#

Thank!

timid dew
#

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"))

scenic furnaceBOT
rancid lark
potent copper
#

note that Typst doesn't enforce the .typ file ending

#

so include "myfile.txt" should work

rancid lark
# potent copper what's the problem with that?

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

rancid lark
#

So I will file a PR for the LSP as well