为什么从命令行运行 LuaLaTeX 不会产生与从 Sublime Text 构建相同的辅助文件?

为什么从命令行运行 LuaLaTeX 不会产生与从 Sublime Text 构建相同的辅助文件?

我正在尝试自动化 LaTeX 构建,工作流程中的一个步骤是从命令行调用 LuaLaTeX,如下所示:

lualatex example.tex

虽然运行此命令会按要求输出 PDF,但缺少需要出现在右上角的图像。

话虽如此,Ctrl + B在 Sublime Text 中按下 (build)(将 builder 设置为 LuaLaTeX 后)会生成 PDF,其中所需图片位于正确的位置。我想知道这里幕后到底发生了什么才能实现这一点。显然,仅仅打字lualatex example.tex是不够的,那么我遗漏了什么?

据我所知,调用 Sublime Text LuaLaTeX 构建器会aux/在工作目录中生成一个名为的目录。里面aux/有许多辅助文件:

example.aux
example.log
example.fdb_latexmk
example.fls
example.synctex.gz
example.pdf

但是,仅lualatex example.tex从命令行运行只会生成该列表中的前两个文件,我怀疑这可能是我的图片未显示在 PDF 中的部分原因。

将图片放入文档的方法有点复杂。图片的文件路径存储在名为的 JSON 文件中parameters.json。此路径导入到我的.tex文件中,如下所示:

\begin{document}
    \begin{luacode}
        require("lualibs.lua")

        function getjsonfile (file)
            local f, s
            f = io.open(file, 'r')
            s = f:read('*a')
            f.close()
            return s
         end

        paramtable = utilities.json.tolua(getjsonfile('parameters.json'))
    \end{luacode}

    \Header{\luadirect{
        local path = paramtable["image_path"]
        tex.print(path)}}

\end{document}

这里,\Header是一个宏,它接受图像的有效文件路径或字符串none,在这种情况下不显示任何图像。

由于密钥image_path指向一个文件(忽略扩展名),\Header{}接收其参数,理论上一切都应该没问题。

我对 LaTeX/LuaLaTeX 还很陌生,因此如果能帮我弄清楚从 Sublime Text 构建和直接从命令行运行命令之间到底有什么区别,我将不胜感激。我在这里提供了一个最小工作示例,以及我的LaTeXTools.sublime-settings文件的副本,其中包含有关我的构建的信息。

最大能量损失 - parameters.json:

{"image_path": "./picture"}

最大能量损失 - example.tex:

\documentclass[paper=a4,fontsize=11pt]{scrartcl} % KOMA-article class
\usepackage{luacode}
\usepackage[left=1.5cm, right=1.5cm, top=1.5cm, bottom=1.5cm]{geometry}
\usepackage{graphicx}                    % Enable pdflatex
\usepackage{etoolbox}
\usepackage{tikz}
    \usetikzlibrary{calc}   

\newcommand{\placepicture}[4][center]{%
  % [#1]: box anchor: center (default) | 
  %                 south west | west | north west | north |
  %                 north east | east | south east | south | 
  %                 mid west | mid | mid east |
  %                 base west | base | base east 
  % #2: horizontal position (fraction of page width)
  % #3: vertical position (fraction of page height)
  % #4: image name
  %
  \tikz[remember picture,overlay,x=\paperwidth,y=\paperheight]{%
    \node[anchor=#1,inner sep=0pt]
    at ($(current page.south west)+(#2,#3)$) {\includegraphics[width=0.2\textwidth]{#4}};
  }%
}

\newcommand{\Header}[1]{
    \edef\mytemp{{#1}}%
    \expandafter\ifstrequal\mytemp{none}{}{\placepicture[north east]{0.9}{0.98}{#1}}
}

%%% ------------------------------------------------------------
\begin{document}
    \begin{luacode}
        require("lualibs.lua")

        function getjsonfile (file)
            local f, s
            f = io.open(file, 'r')
            s = f:read('*a')
            f.close()
            return s
         end

        paramtable =  utilities.json.tolua(getjsonfile('parameters.json'))
    \end{luacode}

    \Header{\luadirect{
            local path = paramtable["image_path"]
            tex.print(path)}}

  Some normal body text here.

\end{document}

LaTeXTools.sublime-settings(不是整个文件,只是构建设置):



{
// ------------------------------------------------------------------
// Temporary file settings
// ------------------------------------------------------------------
    // Ends of the names of temporary files to be deleted
    "temp_files_exts": [
        ".blg",".bbl",".aux",".log",".brf",".nlo",".out",".dvi",".ps",
        ".lof",".toc",".fls",".fdb_latexmk",".pdfsync",".synctex.gz",
        ".ind",".ilg",".idx"
    ],
    // Folders that are not traversed when deleting temp files
    "temp_files_ignored_folders": [
        ".git", ".svn", ".hg"
    ],

// ------------------------------------------------------------------
// Platform settings: adapt as needed for your machine
// ------------------------------------------------------------------

    "linux" : {
        // Path used when invoking tex & friends; MUST include $PATH
        "texpath" : "$PATH:/usr/texbin",
        // Command to invoke Python. Useful if you have Python installed in a
        // non-standard location or want to use a particular version of python.
        // Both Python2 and Python3 are supported, but must have the DBus bindings
        // installed.
        "python": "",
        // The name of the ST2 or ST3 executable. On Ubuntu, both subl and sublime-text are
        // available for ST2; adjust as needed for other platforms, and for ST3
        "sublime": "sublime-text",
        // How long to wait after evince or okular has launched before sending a sync message
        // in seconds, floating point; choose 2.0 or 3.0 on a slower machine, 0.5 on a fast one
        // Note: only tweak this if sync after launching the PDF viewer does not seem to work,
        // or if the PDF viewer opens instantly and you don't want to wait.
        // Default: 1.5 (works on my MBP4,1...)
        "sync_wait": 1.5,
        // Command to invoke Sublime Text. Used if the keep_focus toggle is true.
        // If blank, "subl" or "sublime_text" will be used.
        "sublime_executable": "",
        // how long (in ms) to wait after the jump_to_pdf command completes
        // before switching focus back to Sublime Text. This may need to be
        // adjusted depending on your machine and configuration.
        "keep_focus_delay": 0.5
    },

// ------------------------------------------------------------------
// Output Directory settings settings
// ------------------------------------------------------------------

    // OPTION: "aux_directory"
    // Specifies the auxiliary directory
    // Possible values:
    //
    // ""               the default; does not use any auxiliary directory
    //
    // path             the path to the auxiliary directory; if this is
    //                  not an absolute path it is interpreted as a
    //                  path relative to the main tex file
    //
    // "<<temp>>"       the auxiliary directory will be a temporary
    //                  directory generated in as secure a manner as
    //                  possible; note that this temporary directory
    //                  is only valid until ST is restarted and will
    //                  be deleted on the next start-up
    //
    // "<<project>>"    this creates an auxiliary directory in the same
    //                  folder as the main tex file; the name is the
    //                  MD5 hash of the absolute path of the main file;
    //                  unlike <<temp>> this directory will persist
    //
    // "<<cache>>"      this creates an auxiliary directory in the ST
    //                  cache directory on ST3 or a suitable directory
    //                  on ST2; unlike <<temp>> this directory will
    //                  persist; unlike <<project>>, it will not be
    //                  in the same directory as the main tex file
    //
    // NOTE: This setting will be overridden by the corresponding
    // %!TEX directive if any; also, while it is possible to define
    // a global value here, it may make more sense to define this
    // value in your project settings if you use STs project feature
    // if you do so, however, note that the path will be interpreted
    // relative to the location of your project file

    "aux_directory": "",

    // OPTION: "output_directory"
    // Specifies the output directory

    "output_directory": "./aux",

    // OPTION: "jobname"
    // Specifies the jobname to use when building the document

    "jobname": "",

    // OPTION: "copy_output_on_build"
    // Specifies whether to copy the final PDF file to the same folder
    // as the main tex file; if it is neither true nor false it must be
    // as list of extensions of the files to copy into the same folder as
    // the main tex file; this  only applies if an output directory is
    // set via a setting or a `%!TEX` directive

    "copy_output_on_build": true,

// ------------------------------------------------------------------
// Build engine settings
// ------------------------------------------------------------------

    // OPTION: "builder"
    // Specifies a build engine
    // Possible values:
    //
    // "default" or ""  the default built-in build engine; currently
    //                  this is the same as "traditional"
    //
    // "basic"          invokes pdflatex / xelatex / lualatex as
    //                  needed, then biber / bibtex and pdflatex /
    //                  xelatex / lualatex again if needed. Unlike
    //                  the "simple" builder this supports most of
    //                  LaTeXTools builder features.
    //
    // "script"         external script: invokes the set of commands
    //                  specified in the "script_commands" setting
    //                  in the platform-specific part of the
    //                  "builder_settings"
    //
    // "simple"         invokes pdflatex 1x or 2x as needed, then
    //                  bibtex and pdflatex again if needed;
    //                  intended mainly as a simple example for
    //                  people writing their own build engines.
    //
    // "traditional"    replicates the 'old' system based on
    //                  latexmk (TeXLive) / texify (MiKTeX)
    //
    // custom name      you can also use third-party build engines;
    //                  if so, set the "builder_path" option below
    //
    // NOTE: custom builders CANNOT have the same name as an existing
    // built-in build engine (including "default")

    "builder": "basic",

    // OPTION: "builder_path"
    // If non-empty, specifies a path to a custom builder, relative to the
    // Sublime Text Packages directory.
    // For instance, "User/builders" (on Windows: "User\builders") is a good
    // choice if you roll your own.
    // (Note: if you choose "User", you may get a Python import error in the
    // console, but things will still work).
    // Leave empty ("") for a built-in builder.

    "builder_path": "",

    // OPTION: "builder_settings"
    // Specify builder-dependent settings and preferences
    // Possible values: see README or documentation provided with
    // third-party build engine.
    // Builder setting can be general or OS-dependent

    "builder_settings" : {

        // General settings:
        // See README or third-party documentation

        // (built-ins): true shows the log of each command in the output panel
        "display_log" : false,
        // Enable this when using the minted package 
        "options": ["--shell-escape"],

        // Platform-specific settings:
        "osx" : {
            // See README or third-party documentation
        },

        "windows" : {
            // See README or third-party documentation
        },

        "linux" : {
            // See README or third-party documentation
        }
    },

// ------------------------------------------------------------------
// Build panel and phantoms settings
// ------------------------------------------------------------------
    // OPTION: "highlight_build_panel"
    // adds syntax highlighting to the build panel so that errors, warnings, etc.
    // show up in different colors; if set to false, the panel will be left as-is.
    "highlight_build_panel": true,


    // OPTION: "hide_build_panel"
    // level to hide the build panel after the build is finished
    // Possible values are:
    // "always" (hide the panel even if the build failed),
    // "no_errors" (only hide the panel if the build was successful even with warnings),
    // "no_warnings" (only hide the panel if no warnings occur)
    // "no_badboxes" (only hide the panel if no badbox messages occur when badboxes are enabled) and
    // "never" (default, never hide the build panel)
    "hide_build_panel": "no_badboxes",

    // OPTION: "display_bad_boxes"
    // controls whether or not to display any bad boxes in the build output
    // if this is not set to true, the setting "no_badboxes" for
    // "hide_build_panel" is equivalent to "no_warnings"
    "display_bad_boxes": false,

    // OPTION: "show_error_phantoms"
    // (ST3, Build 3118+ only)
    // level to show error phantoms in the file
    // Possible values are:
    // "none" (don't show any phantoms at all)
    // "errors" (only show errors, which breaks the compilation)
    // "warnings" (default, show errors and warnings)
    // "badboxes" (show errors, warnings, and badboxes)
    "show_error_phantoms": "warnings",

    // number of seconds to display the "build succeeded" or "build failed"
    // message
    "build_finished_message_length": 2.0,

// ------------------------------------------------------------------
// Viewer settings
// ------------------------------------------------------------------
    // OPTION: "viewer"
    // Specifies which viewer to use
    // Possible values:
    //
    // "default" or ""  the default viewer for your platform, which
    //                  is sumatra on Windows, skim on OS X and
    //                  evince on linux
    //
    // "command"        invokes a viewer based on commands configured
    //                  in viewer settings below; see the README
    //                  for details
    //
    // "evince"         uses Evince; this is the default on linux
    //
    // "okular"         uses Okular to open the pdf
    //
    // "preview"        uses Preview.app to open the pdf
    //
    // "skim"           uses Skim to open the pdf; this is the
    //                  default on OSX
    //
    // "sumatra"        uses SumatraPDF; this is the default on
    //                  Windows
    //
    // "zathura"        uses Zathura to open the pdf
    "viewer": "",

    // OPTION: "viewer_settings"
    // Specify viewer-dependent settings and preferences
    // Possible values: see README or documentation provided with
    // third-party viewer.
    // Viewer settings can be general or OS-dependent
    "viewer_settings": {
        // Platform-specific settings:
        "osx" : {
            // See README or third-party documentation
        },

        "windows" : {
            // See README or third-party documentation
        },

        "linux" : {
            // See README or third-party documentation
        }
    },

    // OPTION: "open_pdf_on_build"
    // specifies whether LaTeXTools should open the PDF file on a
    // successful build. If set to false, the PDF file won't be opened
    // unless explicitly launched using C-l,v or C-l,j
    "open_pdf_on_build": true,

    // OPTION: "disable_focus_hack"
    // if set to true, this will stop LaTeXTools from attempting to steal focus
    // from the viewer. NOTE: This does not mean that the *viewer* won't steal
    // the focus, only that LaTeXTools won't try to steal the focus back.
    "disable_focus_hack": false,

// ------------------------------------------------------------------
// Opening files included into the tex source code
// ------------------------------------------------------------------

    // image types you use in latex
    // these types will be used for autocompletion and
    // opening of included images, when no extension is written
    "image_types": ["png", "pdf", "jpg", "jpeg", "eps"],


// ------------------------------------------------------------------
// Cache options
// ------------------------------------------------------------------

    // settings for caches to update on load
    // leaving these as `true` will ensure LaTeXTools pre-caches the appropriate
    // data when a TeX document is loaded; setting these to `false` will
    // cause the cache to be built when first needed
    // "cache_on_load": {
    //  // analysis: the internal view that LaTeXTools has of your document
    //  "analysis": true,
    //  // bibliography: ensures the bibliography is parsed and cached
    //  "bibliography": true
    // },

    // settings to update caches when a document is saved
    // leaving these as `true` will ensure LaTeXTools reloads the data on save,
    // if necessary; setting these to `false` will cause the cache to be
    // re-built according to its rules
    // "cache_on_save": {
    //  // analysis: the internal view that LaTeXTools has of your document
    //  "analysis": true,
    //  // bibliography: ensures the bibliography is parsed and cached
    //  "bibliography": false
    // },

    /* The life-span of the local cache.
    After this life-span the local cache will automatically be invalidated and refreshed.
    You can invalidate the cache manually by removing all temporary files `C-l,backspace`.
    If the value is smaller then the functionalities are more up-to-date,
    but more recalculations might decrease the performance.

    The format is "X d X h X m X s", where X is a natural number
    "s" stands for seconds, "m" for minutes, "h" for hours, and "d" for days.
    Missing fields will be treated as 0 and white-spaces are optional.
    Hence you can write "1 h 30 m" to refresh the cached data every one and a half hours.
    If the string is invalid the default value (30 minutes) will be used.
    If you use `infinite` the cache will not invalidated automatically.
    */
    "local_cache_life_span": "30 m"
}

我已将两次尝试的 LaTeX 日志的差异包含在内:

  • 图像已成功显示。
  • 没有显示图像的那个。

日志差异:

1,2c1,2
< This is LuaTeX, Version 1.0.4 (TeX Live 2017)  (format=lualatex 2017.11.12)  16 OCT 2019 22:54
<  system commands enabled.
---
> This is LuaTeX, Version 1.0.4 (TeX Live 2017)  (format=lualatex 2017.11.12)  16 OCT 2019 22:55
>  restricted system commands enabled.
37c37
< luaotfload | main : initialization completed in 0.256 seconds
---
> luaotfload | main : initialization completed in 0.263 seconds
817,818c817
< (./aux/example.aux)
< \openout1 = example.aux
---
> No file example.aux.
819a819
> \openout1 = example.aux
834d833
< 
955c954,958
< <./picture.jpg>] (./aux/example.aux))
---
> <./picture.jpg>] (./example.aux)
> 
> LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
> 
> )
958c961
<  18576 strings out of 494483
---
>  18571 strings out of 494483
967c970
< Output written on example.pdf (1 page, 53837 bytes).
---
> Output written on example.pdf (1 page, 53834 bytes).

差异显示错误:No file example.aux,但这很奇怪,因为该文件正在生成。

如果我可以提供任何其他信息,请告诉我。

答案1

你的 diff 中有趣的部分是以下部分

817,818c817
< (./aux/example.aux)
< \openout1 = example.aux
---
> No file example.aux.
819a819
> \openout1 = example.aux
834d833
< 

以及

> LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

在手动运行中。

这表明在 Sublimelatexmk运行中 (Lua)LaTeX 可以读取.aux文件,但在您手动启动的lualatex运行中却没有.aux文件。

.aux文件是 LaTeX 用来与自身通信的临时辅助文件,因为它无法预测未来。该.aux文件捕获有关文档的相关信息(页面引用、标签定义等),这些信息在文档流中发布之前可能需要。它会在文档开头读取,以便在需要时从一开始就提供信息。该文件会在每次 LaTeX 运行期间写入(除非另有明确要求)。有关需要这样做的原因的更多背景信息,请参见以下\label示例了解引用和标签的工作原理

这告诉我们,.log您的 Sublimelatexmk运行可能是.log在您的文档上后续运行的 LuaLaTeX 文件,而您的手动lualatex运行是在您的文档上第一次运行(或者临时文件已被删除)。

Indeed 的latexmk编写目标是自动运行 LaTeX 和 BibTeX 等辅助程序,makeindex以便文档能够正常显示。如果您lualatex手动运行,则必须自行处理。

在这种情况下,lualatex对文档运行两次可能已经足够了(你可能希望运行三次,以确保万无一失)。无论如何,你都需要确保你的.log文件不会显示

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

再也没有了。

跑步

lualatex example
lualatex example

或者,如果你愿意,也可以latexmk从命令行使用

latexmk -lualatex example

相关内容