4

I am still a novice in this field, writing only basic papers with Tex. Altough my question may still lay beyond my practice I would like to ask if any Tex is able to load data (texts and pictures specificly) from SQL database, like Helios Inuvio for example? My desire is to create reports via Tex from the database. Do not need specific answer, at least what to do to go further.

John
  • 41
  • There are some related questions here on the site, mostly a bit older bit probably still relevant, for example https://tex.stackexchange.com/questions/3697/is-it-possible-to-connect-a-database-to-latex-to-produce-data-driven-documents and https://tex.stackexchange.com/questions/48193/reading-data-from-a-relational-database-into-a-latex-table. Links taken from the Related section with question links on the right side of this question page, underneath the advertisement, you may find other interesting information there as well. – Marijn Feb 03 '21 at 07:42
  • 1
    Even if it were somehow possible, it would be much cleaner to export the data from SQL with a separate script, and then generate the Tex from it. – Polygnome Feb 03 '21 at 15:04
  • To understand.. The main idea was to keep specific data updated according to the changing data in database, every time new PDF is generated. – John Feb 04 '21 at 10:21

2 Answers2

4

there are basically two approaches you can take:

  • Use shell-escape: If you pass -shell-escape to TeX, then you can run arbitrary shell commands and read their output. Since many databases come with command line cliens which are more or less scriptable, this allows you to access the database.

  • Or use LuaTeX. LuaTeX allows you to use arbitrary Lua code, so you can integrate it with any Lua SQL library. See e.g. Using LuaLaTeX and SQLite3 for SQLite or the LuaSQL library for a more general system. These require you to install these libraries separately, they do not come as part of your typical TeX distribution.

3

I don't know if you can do it directly with TeX (probably can with some arcane code), however if you are interested in dynamic reports it is worth looking at either

Both R and Python can work really well with SQL databases, and process data, making them much more flexible than vanilla TeX.

I have personal experience with sweave and knitr, and they both work remarkably well and consistently, once you take some time to understand their underlying philosophy and differences from TeX. I haven't really managed to start with Pweave, but its in my scopes .

NMech
  • 273
  • 1
  • 5
  • FYI, knitr does not force you to use markdown, it can also deal with LaTeX in Rnw documents. See Chapter 3.2.1 if the knitr book. – CL. Feb 03 '21 at 15:32