lualatex 및 mongo 관련 문제

lualatex 및 mongo 관련 문제

lualatex와 mongo에 문제가 있습니다

% !config
% arara: lualatex :{shell : yes , synctex : yes}
% arara : tikzmake :{ jobs : 1, force : yes}
\documentclass[12pt,a4paper]{book}
\usepackage{Bibles}
\usepackage{lipsum}
%\usepackage[utf8x]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\author{PADDEU Dylan}
\title{bible accessibilité}
\usepackage{ifluatex}
\usepackage{luatexbase}
\usepackage{luacode}
\begin{document}
\maketitle
\begin{luacode*}
    dofile("bible.lua")
\end{luacode*}
\end{document}

내 루아 코드:

mongo = require('mongo')
client = mongo.Client('mongodb://127.0.0.1:27017')
ERP = client:getCollection('bible','Etablissement Recevant du Public (ERP)')
vote = client:getCollection('bible','bureau de vote')
enseignement = client:getCollection('bible',"etablissement enseignement")
logement = client:getCollection('bible','logement')
transport = client:getCollection('bible','transport')
voirie = client:getCollection('bible','voirie')
stationnement = client:getCollection('bible','carte de stationnement')
travail = client:getCollection('bible','lieux de travail')
CCIA  = client:getCollection('bible','commission communale et intercommunale accessibilite')
CCDSA = client:getCollection('bible','COMMISSION CONSULTATIVE DEPARTEMENTALE DE SECURITE ET D’ACCESSIBILITE')
formation_acces = client:getCollection('bible','formation accessibilite')
test1 = client:getCollection('bible','test')
function essais()
    local q = mongo.BSON{_id=9}
    local r = test1:findOne(q):value()
    print("nom du domaine",r.domaine)
end

그리고 문제

 module 'mongo' not found:
    no field package.preload['mongo']
    [kpse lua searcher] file not found: 'mongo'
    [kpse C searcher] file not found: 'mongo'
stack traceback:
    [C]: in function 'require'
    ./bible.lua:1: in main chunk
    [C]: in function 'require'
    [\directlua]:1: in main chunk.
\luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }

관심

답변1

나는 Luatex를 다루는 사람 이상도 아니고 실제로 Lua 사용자라고 주장할 수도 없습니다. 나보다 지식이 풍부한 사람들이 내 실수를 용서해 주기를 바라지만 최소한 내 경험을 보고할 수는 있습니다.

Luatex 내에서는 TeX의 모듈을 사용할 때 Luatex가 일반적인 메커니즘이 아닌 TeX의 검색 메커니즘을 사용하도록 package.searchers대체되었습니다 . require이는 실제로 Luatex 내에서 Lua를 실행할 때 일반 시스템 Lua가 찾는 모듈을 찾지 못한다는 것을 의미합니다. (건축에 대해서는 잘 모르지만,추정하다이는 다른 병렬 구조를 안전하게 유지하고 다른 모듈이 다른 곳에 설치되어 있어도 LuaTeX가 항상 TeX에 적합한 모듈을 선택하도록 하기를 원하기 때문에 의도적인 것입니다.)

실제로 이는 luarocks를 통해 lua 모듈을 설치한 경우 찾을 디렉터리 내에 복사본을 배치하거나 심볼릭 링크를 포함해야 함을 의미합니다 kpathsea. Luarocks는 내가 아는 한 매우 단순한 것이며 편리한 디렉토리에 파일을 덤프하기만 하면 해당 파일을 찾아서 링크하거나 복사할 수 있어야 합니다. 문서에서는 "물론 대체 로더를 작성하고 이를 매크로 패키지에서 사용하는 것은 별 일이 아닙니다"라고 귀엽게 경고하고 있지만, (나 같은!) 우리 중 일부에게는 꽤 큰 일이 될 수 있습니다.

순수 Lua가 아니지만 C에서 컴파일된 코드에 의존하는 lua 모듈을 사용하는 경우 이것이 어떻게 작동하는지 경험이 없습니다. Luatex 자체는 이미 그러한 라이브러리(예: slnunicode)를 연결하고 있지만 이것이 귀하에게 어떤 영향을 미칠 수 있는지 전혀 모릅니다. 유감스럽게도 사용 사례가 있습니다. 나는 그것이 "그냥 작동"하기를 바라지만 ...

독립 실행형과 TeX에 연결된 것으로 테스트하려는 무언가를 구축할 때 나는 시행착오를 통해 다음을 발견했습니다.

  • 한 환경 또는 다른 환경에서만 실행되는 코드가 필요한 경우(아마도) lua.versionLuatex에서 실행 중인 경우 정의될 정의를 테스트하세요. 엄밀히 말하면 lua를 확인하는 것만으로도 충분하다고 생각합니다. (그리고 가 정의되지 않으면 오류가 발생하기 때문에 확인하는 것은 lua.version안전하지 않습니다 .)lua

    if lua and lua.version then
     -- we're in LuaTeX
    else
     -- we're not
    end
    
  • 병렬로 개발하는 한 가지 방법은 texluaLua 인터프리터로 사용하는 것입니다. 그렇게 하면 당신은~ 할 것이다항상 luatex의 일부인 정적으로 링크된 라이브러리(예: LPEGslnunicode, 즉 필요 없이 require)에 자동으로 액세스합니다. 그리고 스크립트는 TeX 문서의 호출을 통해 실행되는 것처럼 "마치" 실행됩니다. 하지만 문제가 있습니다. Texlua는 자동으로 함수를 "찾지" 않으므로 kpathsea수행할 작업을 "알려주어야" 합니다.

    kpse.set_program_name("kpsewhich") -- or whatever
    

    이제 예를 들면

    local xml = require("luaxml-domobject")
    

    :를 사용하여 TeX 디렉토리 트리에서 적절한 모듈을 찾을 것입니다 . 해당 마법이 없으면 모듈을 찾을 수 없다는 kpsewhich음울한 불만을 갖게 될 것입니다 . package.loader아니면 더 나쁜 결과를 얻게 될 것입니다.그 이름을 가진 모듈이지만 Luatex가 "실제로" 책임을 맡을 때 얻을 수 있는 모듈은 아닙니다.

설명보다 아래 코드가 더 따라하기 쉬울 것 같아요! 이를 실행하면 texlua하나의 출력을 얻게 됩니다. 출력이 약간 다르지만 lua두 경우 모두 작동합니다.

local luatexing = lua and lua.version

-- local lpeg shadows global lpeg if luatex is running this
local lpeg = lpeg

if luatexing then
   kpse.set_program_name("kpsewhich")
else
   -- if luatex is not in charge we need to require the library
   lpeg = require("lpeg")
end

-- The output here will differ depending on
-- whether we have luatex (with statically
-- linked unicode library) or not. Of course,
-- we could then `require` something
-- appropriate.

if luatexing then
   io.write(unicode.utf8.lower("Ê") .. "\n")
else
   io.write(string.lower("Ê") .. "!\n")
end

-- But this will work in either case: with
-- luatex via the statically linked lpeg
-- library. With regular lua via the require

j = lpeg.P("a matcher")

io.write(j:match("a matcher") .. "\n")

내가 실제로 탐구하지 않았기 때문에 내가 모르는 것은 kpathsea이미 설정되어 있는 TeX 문서에서 직접 호출될 파일에서 설정을 제거하기 위해 주의해야 하는지 여부입니다. 그러나 개발 목적으로 이 설정이 필요한 경우 TeX 실행 내에서 호출될 때 스크립트가 해석되는 방식에 합리적으로 근접할 수 있습니다.

관련 정보