I would like to create a book (to be exact a psalter). Basically it is a database issue. I have on one hand a tex document (to be exact currently it's still a word document) with all the psalms and on the other the book I want where I want to insert selected psalm from the first document. I don't know how to start to keep it simple. I look to datatool but can a psalm be an entry ? Or Should a create a document for each psalm that will be called ? If yes, how can I do it quickly ? Can I call the psalm base on its title in the document containing all the psalm ?

  • It's unclear why you would need a database for this, unless you envision changing the order of the included psalms on demand, or including only some and not others. But even then, I don't think you need a database. Surely this is no different that any other large-ish document, where it makes sense to have each psalm as a separate file and then a master document that simply uses \include or \input to input them.
    – Alan Munn
    Apr 18, 2020 at 16:08
  • Of course you could make the master document simpler by naming each psalm file psalm-x.tex and then use a loop over x, but this is really a matter of whether you want a 3 line master document or a 150 line master document. If you do need mix and match versions, then just keep a database of the filenames and use datatool or similar processing to do the different versions.
    – Alan Munn
    Apr 18, 2020 at 16:11
  • Thanks @AlanMunn yes I would like to change the order of the included psalms on demand etc. I was thinking about \include or \input but that mean I need to create a a document for each psalm that is to say 150 documents... Is there an easy way to create those documents ?
    – JBOP
    Apr 18, 2020 at 16:17
  • Since your source is in Word, it's probably fastest to simply cut and paste each into a new .tex document. This is something you do only once. xkcd.com/1205 Since you're converting from Word, I would recommend using a unicode engine like XeLaTeX or LuaLaTeX. But I suspect there may be more issues lurking in the conversion than in the creating 150 files.
    – Alan Munn
    Apr 18, 2020 at 16:26
  • There’s one of these for a different set of scriptures. You might look at its source.
    – Davislor
    Sep 15, 2020 at 20:18

2 Answers 2


A database can contain whatever you want as data associated to a key. Even a longish text. Just need a database (-style package, you presumably just have a single key --psalm number/name-- and associated data --text--) package to handles that.

The Linux (BSD original, some work on porting to other platforms) strfile(1) utility (part of fortune-mod here) takes files made of paragraphs and creates a file indexed with the paragraphs for random access, you'd need to hack it to add a key. It could give some inspiration.

Or kludge up a script in some scripting language that reads text with some marker like %% identifier lines, and reads a file containing something like:

Lorem ispum dolor sit amet, ...
Sed ut perspiciatis unde omnis iste natus error sit...

looks up the identifier and replaces by the following text.

  • I haven't try yet but according to datatool user guide, we cannot have paragraph break (and maybe no other command...)
    – JBOP
    Apr 19, 2020 at 7:55

I have found a solution to call the psalm I need from a master file composed of all the palms. So, in a .tex file, I have the "database" containing all the psalms. Each psalm is within a command which serve as a identifier. Here is an example:

Lorem ipsum...
Sed ut perspiciatis unde omnis iste natus error sit...

In order to call the psalm, I need to call the macro \PsalmI for example. However, as the psalm I called based on the content of another databased, I have created another command \Psalmus which name depends on the variable:

\newcommand{\Psalmus}[1]{\csname Psalm#1\endcsname}

To call the psalm, I just need to call it through the macro: \Psalmus{II} for example. This calls the macro \PsalmII and displays the second psalm.

This solution is based on Ulrike Fischer's solution to this topic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.