wtsnjp / llmk

Light LaTeX Make
https://ctan.org/pkg/llmk
MIT License
110 stars 5 forks source link

bibtex does not run when .bib has different basename #9

Closed sudotac closed 3 years ago

sudotac commented 3 years ago

Summary

When .bib has different basename from .tex, bibtex does not run.

Environment

TeX distribution : TeX Live 2020/Arch Linux llmk : master (916c6bd) (llmk.lua is symlinked as llmk.)

How to Reproduce

Here is a small example.

test.tex

% +++
% sequence = ["latex", "bibtex", "dvipdf"]
% latex = "uplatex"
% bibtex = "bibtex"
% dvipdf = "dvipdfmx"
% +++
\documentclass[dvipdfmx,uplatex,a4j]{jsarticle}
\begin{document}
citation\cite{knuth1997art}

\bibliographystyle{abbrv}
\bibliography{testref}
\end{document}

testref.bib is located in the same directory.

$ llmk -sv test.tex
llmk info: Beginning a sequence for "test.tex"
llmk info: Running command: uplatex -interaction=nonstopmode -file-line-error -synctex=1 "test.tex"
llmk info: Running command: uplatex -interaction=nonstopmode -file-line-error -synctex=1 "test.tex"
llmk info: Running command: dvipdfmx "test.dvi"

bibtex doesn't run.

Possible Solution

bibtex processes .aux and produces .bbl, so the default value of programs.bibtex.target should be %B.aux. (Currently the default value is set as %B.bib in this line : https://github.com/wtsnjp/llmk/blob/916c6bd/llmk.lua#L90 )

For your information, if programs.bibtex.target is set manually like this, then it works.

test2.tex

% +++
% sequence = ["latex", "bibtex", "dvipdf"]
% latex = "uplatex"
% dvipdf = "dvipdfmx"
%
% [programs.bibtex]
% command = "bibtex"
% target = "%B.aux"
% +++
% -- (snip : same as test.tex) --

testref.bib is located in the same directory.

$ llmk -sv test2.tex
llmk info: Beginning a sequence for "test2.tex"
llmk info: Running command: uplatex -interaction=nonstopmode -file-line-error -synctex=1 "test2.tex"
llmk info: Running command: uplatex -interaction=nonstopmode -file-line-error -synctex=1 "test2.tex"
llmk info: Running command: bibtex "test2"
llmk info: Running command: uplatex -interaction=nonstopmode -file-line-error -synctex=1 "test2.tex"
llmk info: Running command: uplatex -interaction=nonstopmode -file-line-error -synctex=1 "test2.tex"
llmk info: Running command: dvipdfmx "test2.dvi"

bibtex runs correctly.

I usually use only bibtex and upbibtex so I'm not sure about other environments... but I think other bibtex-like programs also expect .aux files.

wtsnjp commented 3 years ago

Thanks for your suggestion. In the programs.bibtex table of llmk, a bib database should be specified for the target rather than an aux file. That is, for instance in your case, the desired configuration in terms of the program design is the following.

% +++
% sequence = ["latex", "bibtex", "dvipdf"]
% latex = "uplatex"
% dvipdf = "dvipdfmx"
%
% [programs.bibtex]
% target = "testref.bib"
% +++

Specifying an aux file does work in some cases including yours, but llmk should know which is the bib database for your document. At this point, this is indeed not that much important, but I have a plan to persistence the internal file database (fdb) of llmk by writing its content to an external file, which is similar to \jobname.fdb for latexmk. With the permanent fdb feature, the bibtex program should be run only if the database is updated; for this purpose, llmk should recognize a bib database as a target.

Another problem with making the aux file (%B.aux) as the default target is that it will result in an error if an author does not intend to use the bibliography feature of LaTeX. As a concrete example, with your proposing default configuration (#10), it will result in an error to run it over the default.tex:

$ llmk -v default.tex
...
llmk info: Running command: bibtex "default"
This is BibTeX, Version 0.99d (TeX Live 2020)
The top-level auxiliary file: default.aux
I found no \citation commands---while reading file default.aux
I found no \bibdata command---while reading file default.aux
I found no \bibstyle command---while reading file default.aux
(There were 3 error messages)
llmk error: Fail running bibtex "default" (exit code: 512)

Obviously, the default configuration should not try to run a command that results in an error in typical valid LaTeX documents.

In summary, the llmk users should explicitly specify bib databases for the target in the programs.bibtex table if they want to use a filename other than %B.bib.

sudotac commented 3 years ago

Thanks for the detailed description!

First, I should apologize that I didn't notice some errors in CI tests, and I didn't think of example documents. I will close the PR(#10) later.

I have a plan to persistence the internal file database (fdb) of llmk

It looks good to me, and I understand why llmk needs a path of a bib database, not that of an aux file.

A possible problem with this approach is the lack of support for multiple bib databases. llmk can only accept a bib database in programs.bibtex.target for now while \bibliography can accept multiple arguments. To my knowledge, the aux file is always a single file, but the specified bib database(s) in a LaTeX document may be multiple. I think it would be better programs.bibtex.target is an array of strings, not a string.

wtsnjp commented 3 years ago

Yes, that is also my concern. Not only for BibTeX but in general, there should be cases that multiple targets are desired. I will think about how to address this demand either by making a breaking change on the target key or with a better solution.

koppor commented 3 years ago

In summary, the llmk users should explicitly specify bib databases for the target in the programs.bibtex table if they want to use a filename other than %B.bib.

For me, llmk is a tool with very little configuration. As usual, when leaving the path of convention one needs to configure it. - In my concrete case, there is \bibliography{bib/literature}, which is not recognized automatically. Using the configuration works.

In case there was no bib "found" by llmk, could it output that at the end of the run? In that way, new users wondering why bibliography references are undefined, could be supported.

wtsnjp commented 3 years ago

With -drun flag, it will show that information.

llmk debug-run: Preparing for program "bibtex"
llmk debug-run: Skiping "bibtex" because target (test.bib) does not exist

I don't want to show this type of information by default because it will be too noisy.

koppor commented 3 years ago

Thank you for the hint!

I see hundreds of lines of pdflatex output when using "llmk". Thus, I thought two (IMHO important) lines of llmk would cause no harm. -- I just wanted to ensure that users new to llmk and "just want" to compile their (existing) latex documents can do that without consulting a manual, GitHub issues, ... Maybe, latexmk or ltx2any fit better in my view of usage of latex build tools. - Nevertheless, I will try to have latex templates generated by me supporting (latex-template-generator) a "good" llmk config.