You are not logged in.

#1 2017-08-22 18:12:43

71GA
Member
From: Slovenia
Registered: 2012-09-15
Posts: 282

LuaLaTeX and LuaSQL fail to compile my PDF

I am trying to create a LuaLaTeX document which would during the compilation read some values from my MySQL (MariaDB) database and put them into my compiled PDF. For this to compile I need MariaDB database, LuaSQL, and LuaLaTeX.

So I have installed packages mariadb:

[ziga@laptop ~]$ pacman -Qs mariadb
local/libmariadbclient 10.1.26-1
    MariaDB client libraries
local/mariadb 10.1.26-1
    Fast SQL database server, drop-in replacement for MySQL
local/mariadb-clients 10.1.26-1
    MariaDB client tools

lua-sql-mysql:

[ziga@laptop ~]$ pacman -Qs lua
local/lua 5.3.4-2
    Powerful lightweight programming language designed for extending applications
local/lua-sql-mysql 2.3.0-7
    MySQL module for Lua
local/lua52 5.2.4-2
    Powerful lightweight programming language designed for extending applications

and TeX-Live package groups texlive-most and texlive-lang:

[ziga@laptop ~]$ pacman -Qs texlive
local/texlive-bibtexextra 2017.44915-1 (texlive-most)
    TeX Live - Additional BibTeX styles and bibliography databases
local/texlive-bin 2017.44590-2
    TeX Live binaries
local/texlive-core 2017.44918-1 (texlive-most)
    TeX Live core distribution
local/texlive-fontsextra 2017.44818-1 (texlive-most)
    TeX Live - all sorts of extra fonts
local/texlive-formatsextra 2017.44177-2 (texlive-most)
    TeX Live - collection of extra TeX 'formats'
local/texlive-games 2017.44131-1 (texlive-most)
    TeX Live - Setups for typesetting various board games, including chess
local/texlive-humanities 2017.44833-1 (texlive-most)
    TeX Live - LaTeX packages for law, linguistics, social sciences, and humanities
local/texlive-langchinese 2017.44333-1 (texlive-lang)
    TeX Live - Fonts and macro packages to typeset Chinese texts
local/texlive-langcyrillic 2017.44895-1 (texlive-lang)
    TeX Live - Fonts and macro packages to typeset Cyrillic texts
local/texlive-langextra 2017.44908-1 (texlive-lang)
    TeX Live - Bundle of all extra language support
local/texlive-langgreek 2017.44917-1 (texlive-lang)
    TeX Live - Fonts and support for typesetting Greek
local/texlive-langjapanese 2017.44914-1 (texlive-lang)
    TeX Live - Fonts and macro packages to typeset Japanese texts
local/texlive-langkorean 2017.44467-1 (texlive-lang)
    TeX Live - Fonts and macro packages to typeset Korean texts
local/texlive-latexextra 2017.44907-1 (texlive-most)
    TeX Live - Large collection of add-on packages for LaTeX
local/texlive-music 2017.44885-1 (texlive-most)
    TeX Live - Music typesetting packages
local/texlive-pictures 2017.44899-1 (texlive-most)
    TeX Live - Packages for drawings graphics
local/texlive-pstricks 2017.44742-1 (texlive-most)
    TeX Live - Additional PSTricks packages
local/texlive-publishers 2017.44916-1 (texlive-most)
    TeX Live - LaTeX classes and packages for specific publishers
local/texlive-science 2017.44906-1 (texlive-most)
    TeX Live - Typesetting for mathematics, natural and computer sciences

Now to me it looks like I installed even more than I need, but when I try to compile this LuaLaTeX test.tex document:

\documentclass{article}
\usepackage{luacode}

% We execute the .lua file here
\directlua{dofile('test.lua')}

\newcommand{\stranke}{\luadirect{stranke()}}

\begin{document}
    \begin{tabular}{ll}
        \hline
        id stranke & ime \\
        \hline
        \stranke
        \hline
    \end{tabular}
\end{document} 

which also needs this test.lua document:

function stranke ()
    package.cpath = package.cpath .. ";/usr/lib/lua/5.3/luasql/?.so"

    luasql = require "luasql.mysql"

    env = assert (luasql.mysql())
    con = assert (env:connect("linux_krozki","root","123-SwingeR"))
    cur = assert (con:execute("SELECT * FROM stranke"))

    vnos = cur:fetch ({}, "a")

    while vnos do
        
        tex.print(
            string.format([[%s & %s \\]], vnos.id_stranke, vnos.ime)
        )
        vnos = cur:fetch (vnos, "a")
        
    end 

end

I get this error:

[ziga@laptop 003-v1]$ lualatex test.tex
This is LuaTeX, Version 1.0.4 (TeX Live 2017/Arch Linux) 
 restricted system commands enabled.
(./test.tex
LaTeX2e <2017-04-15>
(using write cache: /home/ziga/.texlive/texmf-var/luatex-cache/generic)(using r
ead cache: /var/lib/texmf/luatex-cache/generic /home/ziga/.texlive/texmf-var/lu
atex-cache/generic)
luaotfload | main : initialization completed in 0.273 seconds
Babel <3.12> and hyphenation patterns for 1 language(s) loaded.
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo(load luc: /home/ziga/.texlive/
texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regular.luc)))
(/usr/share/texmf-dist/tex/lualatex/luacode/luacode.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/share/texmf-dist/tex/luatex/luatexbase/luatexbase.sty
(/usr/share/texmf-dist/tex/luatex/ctablestack/ctablestack.sty))) (./test.aux)te
st.lua:9: module 'luasql.mysql' not found:
        no field package.preload['luasql.mysql']
        [kpse lua searcher] file not found: 'luasql.mysql'
        [kpse C searcher] file not found: 'luasql.mysql'
        no file '/usr/local/lib/lua/5.2/luasql.so'
        no file '/usr/local/lib/lua/5.2/loadall.so'
        no file './luasql.so'
        no file '/usr/lib/lua/5.3/luasql/luasql.so'
stack traceback:
        [C]: in function 'require'
        test.lua:9: in function 'stranke'
        [\directlua]:1: in main chunk.
\luadirect ... { \luacode@maybe@printdbg {#1} #1 }
                                                  
l.15         \stranke
                   
? 

It is especially weird, because I explicitly tell Lua where to search for modules (written in C) with:

package.cpath = package.cpath .. ";/usr/lib/lua/5.3/luasql/?.so"

and if i look at package lua-sql-mysql's file list it looks like this:

usr/
usr/lib/
usr/lib/lua/
usr/lib/lua/5.3/
usr/lib/lua/5.3/luasql/
usr/lib/lua/5.3/luasql/mysql.so
usr/share/
usr/share/licenses/
usr/share/licenses/lua-sql-mysql/
usr/share/licenses/lua-sql-mysql/license.html

so if everything was ok file usr/lib/lua/5.3/luasql/mysql.so should exist on my disk and it really does:

[ziga@laptop 003-v1]$ ls /usr/lib/lua/5.3/luasql/
mysql.so

But why wasn't it found during compilation process? Anyone has any ideas what I can do to compile this? Oh and I also asked about this on Stack Overflow where there aren't any answers - there was only a comment which didn't solve my problem.

My Archlinux was fresh installed from scratch a couple of days ago:

[ziga@laptop 003-v1]$ uname -a
Linux laptop 4.12.8-1-ARCH #1 SMP PREEMPT Thu Aug 17 08:37:20 CEST 2017 x86_64 GNU/Linux

C, ARM, ARM assembly, HTML, CSS, JS, Linux

Offline

#2 2017-08-24 21:50:27

71GA
Member
From: Slovenia
Registered: 2012-09-15
Posts: 282

Re: LuaLaTeX and LuaSQL fail to compile my PDF

I don't know why this doesn't work, but I read on the LuaSQL homepage, that LuaSQL can be installed as a Lua extension using LuaRocks. So I  installed a package luarocks and I tried to install it but I get this warning:

[ziga@laptop ~]$ sudo luarocks install luasql-mysql
Installing https://luarocks.org/luasql-mysql-2.3.5-1.rockspec

Error: Could not find header file for MYSQL
  No file mysql.h in /usr/local/include
  No file mysql.h in /usr/include
You may have to install MYSQL in your system and/or pass MYSQL_DIR or MYSQL_INCDIR to the luarocks command.
Example: luarocks install luasql-mysql MYSQL_DIR=/usr/local

How is this possible if I have mariadb (which is a fork of MySQL) installed?

[ziga@laptop ~]$ pacman -Qi mariadb
Name            : mariadb
Version         : 10.1.26-1
Description     : Fast SQL database server, drop-in replacement for MySQL
Architecture    : x86_64
URL             : http://mariadb.org/
Licenses        : GPL
Groups          : None
Provides        : mysql=10.1.26
Depends On      : mariadb-clients=10.1.26  inetutils  libaio  libxml2  pcre  jemalloc  lz4  boost-libs  lzo  libevent  libsystemd
Optional Deps   : galera: for MariaDB cluster with Galera WSREP
                  perl-dbd-mysql: for mysqlhotcopy, mysql_convert_table_format and mysql_setpermission
Required By     : None
Optional For    : vtk6
Conflicts With  : mysql
Replaces        : None
Installed Size  : 167.90 MiB
Packager        : Christian Hesse <arch@eworm.de>
Build Date      : Thu 10 Aug 2017 12:12:46 PM CEST
Install Date    : Fri 18 Aug 2017 11:33:51 PM CEST
Install Reason  : Explicitly installed
Install Script  : Yes
Validated By    : Signature

Is LuaSQL even compatible with MariaDB which is a "Fast SQL database server, drop-in replacement for MySQL"?


C, ARM, ARM assembly, HTML, CSS, JS, Linux

Offline

#3 2017-08-30 16:09:16

71GA
Member
From: Slovenia
Registered: 2012-09-15
Posts: 282

Re: LuaLaTeX and LuaSQL fail to compile my PDF

I am making a small progress... I managed to install LuaSQL using LuaRocks! This is the command I used - I had to add two system paths:

sudo luarocks install luasql-mysql MYSQL_DIR=/usr/bin/ MYSQL_INCDIR=/usr/include/mysql

But still... My project won't compile using LuaLaTeX:

[ziga@laptop 003-v1]$ lualatex test.tex
This is LuaTeX, Version 1.0.4 (TeX Live 2017/Arch Linux) 
 restricted system commands enabled.
(./test.tex
LaTeX2e <2017-04-15>
(using write cache: /home/ziga/.texlive/texmf-var/luatex-cache/generic)(using r
ead cache: /var/lib/texmf/luatex-cache/generic /home/ziga/.texlive/texmf-var/lu
atex-cache/generic)
luaotfload | main : initialization completed in 0.294 seconds
Babel <3.12> and hyphenation patterns for 1 language(s) loaded.
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo(load luc: /home/ziga/.texlive/
texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regular.luc)))
(/usr/share/texmf-dist/tex/lualatex/luacode/luacode.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/share/texmf-dist/tex/luatex/luatexbase/luatexbase.sty
(/usr/share/texmf-dist/tex/luatex/ctablestack/ctablestack.sty)))
No file test.aux.
test.lua:9: module 'luasql.mysql' not found:
        no field package.preload['luasql.mysql']
        [kpse lua searcher] file not found: 'luasql.mysql'
        [kpse C searcher] file not found: 'luasql.mysql'
        no file '/usr/local/lib/lua/5.2/luasql.so'
        no file '/usr/local/lib/lua/5.2/loadall.so'
        no file './luasql.so'
        no file '/usr/lib/lua/5.3/luasql/luasql.so'
stack traceback:
        [C]: in function 'require'
        test.lua:9: in function 'stranke'
        [\directlua]:1: in main chunk.
\luadirect ... { \luacode@maybe@printdbg {#1} #1 }
                                                  
l.14         \stranke

So now I have AUR package installed for LuaSQL alongside with LuaRocks LuaSQL extension. How come this still won't compile using LuaLaTeX?


C, ARM, ARM assembly, HTML, CSS, JS, Linux

Offline

#4 2017-08-31 09:32:16

rtoijala
Member
Registered: 2011-09-11
Posts: 36

Re: LuaLaTeX and LuaSQL fail to compile my PDF

Starting from the files in your first post, all I had to change was "?.so" to "mysql.so" and the module was found.
Then the build hit an error because I did not actually have MariaDB running, but that will probably not be a problem for you.
Why the fix works, I do not know.

Offline

#5 2017-08-31 10:06:35

71GA
Member
From: Slovenia
Registered: 2012-09-15
Posts: 282

Re: LuaLaTeX and LuaSQL fail to compile my PDF

rtoijala wrote:

Starting from the files in your first post, all I had to change was "?.so" to "mysql.so" and the module was found.

Hey! Thank you! This now works! I really have no idea either why this happens, but it looks like it is a problem with Lua to me...

rtoijala wrote:

Then the build hit an error because I did not actually have MariaDB running, but that will probably not be a problem for you.
Why the fix works, I do not know.

This wasn't the problem in my case. I will point some Lua developers to this post so they might find out why this happens...


C, ARM, ARM assembly, HTML, CSS, JS, Linux

Offline

Board footer

Powered by FluxBB