Git Product home page Git Product logo

bazel-latex's Introduction

Bazel rules for LaTeX

This repository provides Bazel rules for LaTeX, inspired by Klaus Aehlig's blog post on the matter.

Instead of depending on the host system's copy of LaTeX, these rules download a modular copy of TeXLive from GitHub. By using fine-grained dependencies, you will only download portions of TeXLive that are actually used in your documents.

As the output of the LaTeX tools is unnecessarily verbose, the main build rules invoke LaTeX using latexrun. Errors and warnings are formatted similar to those generated by Clang.

BibLaTeX is supported by biber and bibtex. Both are obtained from the TeX Live distribution. Latexrun defaults to bibtex. Please specify the command flag mentioned below to build with biber instead.

Using these rules

Add the following to WORKSPACE:

http_archive(
    name = "bazel_latex",
    sha256 = "<checksum>",
    strip_prefix = "bazel-latex-<release>",
    url = "https://github.com/ProdriveTechnologies/bazel-latex/archive/v<release>.tar.gz",
    patches = ["some_patch.patch"], % Optional
)

load("@bazel_latex//:repositories.bzl", "latex_repositories")

latex_repositories()

# Needed for building ghostscript
# Which is needed by dvisvgm,
# dvisvgm is part of the texlive toolchain,
# but cannot produce correct svg from pdf files without dynamically
# linking to ghostscript.
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies()

# mac os shared lib was cumbersome to build via foreign rules so as a temporary
# solution we provide it as a precompiled artifact.
# Consider making it available via bazel_latex binaries repo instead
http_archive(
    name = "ghostscript_macos",
    build_file_content = """
filegroup(
    name = "libgs_macos",
    srcs = glob(["*/*"]),
    target_compatible_with = ["@platforms//os:osx"],
    visibility = ["//visibility:public"],
)
""",
    sha256 = "56b480ebdf34000eac4a29e108ce6384858941d892fd69e604d90585aaae4c94",
    urls = [
        "https://github.com/solsjo/rules_latex_deps/releases/download/v0.9.4/rules_latex_deps_macos-latest.zip",
    ],
)

And add the following load() directive to your BUILD files:

load("@bazel_latex//:latex.bzl", "latex_document")

You can then use latex_document() in BUILD file to declare documents that need to be built.

load("@bazel_latex//:latex.bzl", "latex_document", "latex_to_svg")

latex_document(
    name = "my_report",
    srcs = glob([
        "chapters/*.tex",
    ]) + [
        "@bazel_latex//packages:biblatex",
        "references.bib",
        "//example/example_class:example_class",
    ],
    bib_tool = "biber",  # Is the default
    format = "pdf",  # Is the default
    main = "my_report.tex",
)

latex_to_svg(
    name = "my_svg_report",
    src = ":my_report",
    libgs = select({
        "@platforms//os:osx": "@ghostscript_macos//:libgs_macos",
        "//conditions:default": "@bazel_latex//third_party:libgs",
    }),
)

latex_document(
    name = "my_dvi_report",
    srcs = glob([
        "chapters/*.tex",
    ]) + [
        "@bazel_latex//packages:biblatex",
        "references.bib",
        "//example/example_class:example_class",
    ],
    format = "dvi",
    main = "my_report.tex",
)

# svgs generated from dvis are 'searchable'.
# This is not yet the case for svg generated from pdfs.
latex_to_svg(
    name = "my_dvi_svg_report",
    src = ":my_dvi_report",
)

Note: For OS X, ghostscript for OS X might not be binary compatible with your version of OS X, as it is provided as a precompiled artifact.

Note: For OS X, latex_to_svg makes use of python to find the absolute path of ghostscript. In using python it also assumes that python3 on OS X is located at /usr/local/bin. This is unfortunate, but can be fixed in a later release.

Utilize cmd_flags to provide optional command line arguments.

Commonly reused sources (e.g., templates) can be placed in filegroup() blocks, so that they don't need to be repeated. Those filegroup() could be located not just in the single BUILD file, but in any of sub directories. For example, if you want to include company specific template files which are located in //company_dir directory as company_style, then declare them as like following in company_dir/BUILD file, and include the dependency, like //company_dir:company_style, in latex_repositories.

filegroup(
    name = "company_style",
    srcs = glob([
        ...
    ]),
)

A PDF can be built by running:

bazel build //example:my_report

It can be viewed using your system's PDF viewer by running:

bazel run //example:my_report_view

If you want to get the output from the PDF viewer you can run:

bazel run //example:my_report_view_output

Using packages

By default, latex_document() only provides a version of TeXLive that is complete enough to build the most basic documents. Whenever you use \usepackage{} in your documents, you must also add a corresponding dependency to your latex_document(). This will cause Bazel to download and expose those packages for you. Below is an example of how a document can be built that depends on the Hyperref package.

latex_document(
    name = "hello",
    srcs = ["@bazel_latex//packages:hyperref"],
    main = "hello.tex",
)

This repository provides bindings for most commonly used packages. Please open a pull request if additional bindings are needed.

Local packages

If the desired package to use is not available through bazel-latex, but is available in TeX Live, then it is possible to patch BUILD.bazel in /packages to add support for the desired package locally.

Therefore, clone bazel-latex locally, and make the desired changes to the packages build file. Then, put the output of the diff in some_patch.patch, and update your WORKSPACE accordingly as shown below.

http_archive(
    name = "bazel_latex",
    sha256 = "<checksum>",
    strip_prefix = "bazel-latex-<release>",
    url = "https://github.com/ProdriveTechnologies/bazel-latex/archive/v<release>.tar.gz",
    patches = ["some_patch.patch"],
)

If this solution does not suffice, please feel free to open a PR to add the corresponding package to Bazel LaTeX. In that case, also see CONTRIBUTING.md.

Example

An example is available in the corresponding folder. The example can be executed by running:

bazel run //example:my_report_view

Platform support

These rules have been tested to work on (using bazel 3.2.0):

  • FreeBSD 11.2, building locally.
  • macOS Mojave 10.14, building locally.
  • macOS Catalina 10.15, building locally.
  • Ubuntu 18.04, building locally.
  • Ubuntu 18.04 WSL, building locally.
  • Ubuntu 18.04, building on a Debian 8 based Buildbarn setup.
  • Ubuntu 19.04 (Disco Dingo), building locally.
  • Ubuntu 20.04, building locally.
  • Ubuntu 22.04, github actions
  • Manjaro 18.1.2 (Juhraya), building locally.
  • Windows 10 1803, building on a Debian 8 based Buildbarn setup.

These rules are known not to work on:

  • Windows (paths are unix-style) should be fixed in a PR.

bazel-latex's People

Contributors

axelzvb avatar beneisner avatar dependabot[bot] avatar edschouten avatar fsareshwala avatar jonghoonseo avatar kernald avatar m3rcuriel avatar mickael-carl avatar patbro avatar pawelz avatar phpirates avatar regisd avatar rpennec avatar solsjo avatar tesspib avatar vertexwahn avatar w4-jonghoon avatar zchn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bazel-latex's Issues

How to depend on local packages?

Importing local (in-repository) modules by providing paths to \usepackage is not supported, and breaks entirely if the package is relative. I tried to use latex_package, which basically acts as a filegroup, and as such keeps the file hierarchy. The work-around that I found was to use a local_repository, but given that it's a workspace rule, it's quite convoluted to use.

It would be great to have native support for local packages, maybe through the help of run_lualatex.py which seems to be doing something similar already to copy files around when it's needed.

failure building using pdfpages package

BUILD

load("@bazel_latex//:latex.bzl", "latex_document")

latex_document(
    name = "cover_letter_resume",
    main = "cover_letter_resume.tex",
    srcs = [
        ":cover_letter.pdf",
        ":resume.pdf",
        "@bazel_latex//packages:calc",
        "@texlive_texmf__texmf-dist__tex__generic__ifxetex",
        "@texlive_texmf__texmf-dist__tex__generic__oberdiek",
        "@texlive_texmf__texmf-dist__tex__latex__pdfpages",
        "@texlive_texmf__texmf-dist__tex__latex__eso-pic",
        "@texlive_texmf__texmf-dist__tex__latex__graphics",
        "@texlive_texmf__texmf-dist__tex__latex__oberdiek",
    ],
)

cover_letter_resume.tex

\documentclass{report}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=-]{cover_letter.pdf}
\includepdf[pages=-]{resume.pdf}
\end{document}
$ bazel build src:cover_letter_resume --verbose_failures
INFO: Analyzed target //src:cover_letter_resume (1 packages loaded, 4 targets configured).
INFO: Found 1 target...
ERROR: /home/lahmanja/code/resume/src/BUILD:19:15: LuaLatex src/cover_letter_resume.pdf failed (Exit 1): run_lualatex failed: error executing command 
  (cd /home/lahmanja/.cache/bazel/_bazel_lahmanja/a1e01723933a64fd774eb9f1c6859e9d/sandbox/linux-sandbox/44/execroot/__main__ && \
  exec env - \
    PATH='$PATH:/home/lahmanja/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/var/lib/snapd/snap/bin:/snap/bin/' \
  bazel-out/host/bin/external/bazel_latex/run_lualatex external/texlive_bin__x86_64-linux/kpsewhich external/texlive_bin__x86_64-linux/luatex external/texlive_bin__x86_64-linux/bibtex external/texlive_bin__x86_64-linux/biber external/bazel_latex_latexrun/latexrun cover_letter_resume src/cover_letter_resume.tex bazel-out/k8-fastbuild/bin/src/cover_letter_resume.pdf)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox run_lualatex failed: error executing command 
  (cd /home/lahmanja/.cache/bazel/_bazel_lahmanja/a1e01723933a64fd774eb9f1c6859e9d/sandbox/linux-sandbox/44/execroot/__main__ && \
  exec env - \
    PATH='$PATH:/home/lahmanja/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/var/lib/snapd/snap/bin:/snap/bin/' \
  bazel-out/host/bin/external/bazel_latex/run_lualatex external/texlive_bin__x86_64-linux/kpsewhich external/texlive_bin__x86_64-linux/luatex external/texlive_bin__x86_64-linux/bibtex external/texlive_bin__x86_64-linux/biber external/bazel_latex_latexrun/latexrun cover_letter_resume src/cover_letter_resume.tex bazel-out/k8-fastbuild/bin/src/cover_letter_resume.pdf)
Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox
failed to open file recorder output: [Errno 2] No such file or directory: 'lualatex.fls'

Possibly a dupe/related to #20?

$ uname -a
Linux lahmanja 5.8.14-arch1-1 #1 SMP PREEMPT Wed, 07 Oct 2020 23:59:46 +0000 x86_64 GNU/Linux
$ bazel version
Build label: 3.5.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Sep 14 06:01:07 2020 (1600063267)
Build timestamp: 1600063267
Build timestamp as int: 1600063267

make the viewer helper scripts file agnostic

the viewer script uses the xdg-open program on linux,
i.e. try to find a program that can open the requested file type, and call the program.

native.sh_binary(
name = "{}_view_output".format(name),
srcs = ["@bazel_latex//:view_pdf.sh"],
data = [":{}".format(name)],
args = ["$(location :{})".format(name)] <=== this part how remove the need to use 'find' in the script
tags = tags,
)

then do
input_file="$1"
xdg-open $input_file

Bazel `--incompatible_depset_union` breaks latex build

This line breaks the Bazel flag --incompatible_depset_union as of Bazel 0.26.0rc16.

Error message was:

ERROR: /home/zhongming/git/LogiOcean/examples/latex/BUILD:9:1: in _latex_pdf rule //examples/latex:helloworld:
Traceback (most recent call last):
        File "/home/zhongming/git/LogiOcean/examples/latex/BUILD", line 9
                _latex_pdf(name = 'helloworld')
        File "/home/zhongming/.cache/bazel/_bazel_zhongming/2aea414f4d422ad78870bb37da8563ec/external/bazel_latex/latex.bzl", line 3, in _latex_pdf_impl
                ctx.actions.run(mnemonic = "LuaLatex", executable ...", <4 more arguments>)
        File "/home/zhongming/.cache/bazel/_bazel_zhongming/2aea414f4d422ad78870bb37da8563ec/external/bazel_latex/latex.bzl", line 16, in ctx.actions.run
                toolchain.kpsewhich.files + toolchain.luatex.files
`+` operator on a depset is forbidden. See https://docs.bazel.build/versions/master/skylark/depsets.html for recommendations. Use --incompatible_depset_union=false to temporarily disable this check.
ERROR: Analysis of target '//examples/latex:helloworld' failed; build aborted: Analysis of target '//examples/latex:helloworld' failed; build aborted

Unable to add pgfplots

Trying to add pgfplots, simply defining a latex_package with :pgf and @texlive_texmf__texmf-dist__tex__latex__pgfplots, fails with the following error:

texmf/texmf-dist/tex/latex/pgfplots/pgfplots.sty:102: error: I can't find file `pgfplots.code.tex'
      at \input pgfplots.code.tex
texmf/texmf-dist/tex/latex/pgfplots/pgfplots.sty:102: error: Emergency stop: job aborted, file error in nonstop mode
      at \input pgfplots.code.tex
texmf/texmf-dist/tex/latex/pgfplots/pgfplots.sty: Fatal error (no output file produced)

I'm not too sure where this file is suppose to come from, being generated... but I definitely can't find it. Would anyone have any pointers?

How to make use of the metropolis beamer theme?

I try to make use of the metropolis Beamer theme. My docu.tex looks like this:

\documentclass{beamer}
\usetheme{metropolis}           % Use metropolis theme
\title{Some title}
\date{\today}
\author{Me}
\begin{document}
  \maketitle
  \section{First Section}
  \begin{frame}{First Frame}
    Hello, world!
  \end{frame}
\end{document}

My BUILD.bazel file:

load("@bazel_latex//:latex.bzl", "latex_document")

latex_document(
    name = "prentation",
    srcs = [
        "@bazel_latex//packages:siunitx",
        "@bazel_latex//packages:tikz",
        "@bazel_latex//packages:beamer",
        "@bazel_latex//packages:beamertheme-metropolis",
    ],
    main = "docu.tex",
)

My WORKSPACE.bazel file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "bazel_latex",
    sha256 = "52eff66049f05716889e06ac71fffdc95c3f0270bd354c8e6c502244577f0748",
    strip_prefix = "bazel-latex-1.2.0",
    url = "https://github.com/ProdriveTechnologies/bazel-latex/archive/refs/tags/v1.2.0.tar.gz",
)

load("@bazel_latex//:repositories.bzl", "latex_repositories")

latex_repositories()

When I do a bazel build //... it tells me that the the target "@bazel_latex//packages:beamertheme-metropolis" is not known. I this theme supported at all? You can I use it?

Metric data not found

I am trying to build the template for the webofc class (https://indico.cern.ch/event/773049/attachments/1926162/3253013/epj-woc-latex.zip). I managed to get the missing packages via some extra latex_package, however I now get the following error:

 ERROR: /Users/ktf/work/active/2019-11-chep-alice-data-analysis/BUILD:39:1: LuaLatex paper.pdf failed (Exit 1) python failed: error e
xecuting command python external/bazel_latex/run_lualatex.py external/texlive_bin__x86_64-darwin/kpsewhich external/texlive_bin__x86
_64-darwin/luatex external/bazel_latex_latexrun/latexrun paper template.tex ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
texmf/texmf-dist/tex/latex/base/inputenc.sty: warning: [inputenc] inputenc package ignored with utf8 based engines
template.tex:19: error: Font \T1/txr/m/n/10=t1xr at 10pt not loadable: metric data not found or bad
      at <to be read again>
    from \begin{document}
template.tex:47: error: Font \T1/txss/m/n/14=t1xss at 13.3pt not loadable: metric data not found or bad
      at <to be read again>
    from \maketitle
template.tex:47: error: Font \T1/txss/bx/n/14=t1xbss at 13.3pt not loadable: metric data not found or bad
      at <to be read again>
    from \maketitle
template.tex:47: error: Font \T1/txss/m/n/12=t1xss at 11.4pt not loadable: metric data not found or bad
      at <to be read again>
    from \maketitle
template.tex:47: error: Font \T1/txss/bx/n/12=t1xbss at 11.4pt not loadable: metric data not found or bad
      at <to be read again>

which seems to be related to how lualatex handles fonts. Is this a known issue?

Toolchain error

I am getting a strange error on f9e1532:

BUILD.bazel:

load("@bazel_latex//:latex.bzl", "latex_document", "latex_to_svg")

latex_document(
    name = "examples",
    srcs = [
        "@bazel_latex//packages:tikz",
        "@bazel_latex//packages:verbatim",
    ],
    main = "example_tex.tex",
)

latex_to_svg(
    name = "examples_svg",
    src = ":examples",
)

bazel build //...:examples_svg:

ERROR: /.../BUILD.bazel:14:13: While resolving toolchains for target //...:examples_svg: No matching toolchains found for types @bazel_latex//:latex_toolchain_type.
To debug, rerun with --toolchain_resolution_debug='@bazel_latex//:latex_toolchain_type'
If platforms or toolchains are a new concept for you, we'd encourage reading https://bazel.build/concepts/platforms-intro.

any ideas?

amsfonts not loading correctly

I am trying to use the \mathbb command, but for some reason lualatex doesn't seem to be able to load the fonts correctly even when I include amsmath correctly.

Repro:

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "bazel_latex",
    sha256 = "f81604ec9318364c05a702798c5507c6e5257e851d58237d5f171eeca4d6e2db",
    strip_prefix = "bazel-latex-1.0",
    url = "https://github.com/ProdriveTechnologies/bazel-latex/archive/v1.0.tar.gz",
)

load("@bazel_latex//:repositories.bzl", "latex_repositories")

latex_repositories()

BUILD.bazel

latex_document(
    name = "repro",
    srcs = [
        "@bazel_latex//packages:amsmath",
    ],
    main = "repro.tex",
)

repro.tex

\documentclass{article}
\usepackage{amsfonts}
\begin{document}
$\mathbb{P}$
\end{document}

The resulting error, when running bazel build //:repro:

INFO: Analyzed target //:repro (0 packages loaded, 2 targets configured).
INFO: Found 1 target...
ERROR: <WORKSPACE_ROOT>/BUILD.bazel:13:15: LuaLatex repro.pdf failed (Exit 1) run_lualatex failed: error executing command bazel-out/host/bin/external/bazel_latex/run_lualatex external/texlive_bin__x86_64-darwin/kpsewhich external/texlive_bin__x86_64-darwin/luatex external/texlive_bin__x86_64-darwin/bibtex ... (remaining 5 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
----------------
Note: The failure of target @bazel_latex//:run_lualatex (with exit code 1) may have been caused by the fact that it is running under Python 3 instead of Python 2. Examine the error to determine if that appears to be the problem. Since this target is built in the host configuration, the only way to change its version is to set --host_force_python=PY2, which affects the entire build.

If this error started occurring in Bazel 0.27 and later, it may be because the Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a Python 2 and Python 3 interpreter, respectively. See https://github.com/bazelbuild/bazel/issues/7899 for more information.
----------------
repro.tex:4: error: Font \U/msa/m/n/10=msam10 at 10pt not loadable: metric data not found or bad.<to be read again>
      at $\mathbb
repro.tex:4: error: Font \U/msa/m/n/7=msam7 at 7pt not loadable: metric data not found or bad
      at <to be read again>
    from $\mathbb
repro.tex:4: error: Font \U/msa/m/n/5=msam5 at 5pt not loadable: metric data not found or bad
      at <to be read again>
    from $\mathbb
repro.tex:4: error: Font \U/msb/m/n/10=msbm10 at 10pt not loadable: metric data not found or bad.<to be read again>
      at $\mathbb
repro.tex:4: error: Font \U/msb/m/n/7=msbm7 at 7pt not loadable: metric data not found or bad
      at <to be read again>
    from $\mathbb
repro.tex:4: error: Font \U/msb/m/n/5=msbm5 at 5pt not loadable: metric data not found or bad
      at <to be read again>
    from $\mathbb
repro.tex:4: error: \textfont5 is undefined (character 80)
      at $\mathbb{P}$
There were errors; repro.pdf not updated
Target //:repro failed to build
Use --verbose_failures to see the command lines of failed build steps.

INFO: Elapsed time: 7.304s, Critical Path: 7.15s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Seems similar to #34

no such package '@bazel_latex_latexrun//' caused by patch: command not found

Thanks for wrapping everything in latexrun to improve error logging.

It works fine for me locally (bazel 0.18) but fails on Cirrus (bazel 0.16.1)

ERROR: /tmp/cirrus-ci-build/docs/BUILD:54:1: every rule of type _latex_pdf implicitly depends upon the target '@bazel_latex_latexrun//:latexrun', but this target could not be found because of: no such package '@bazel_latex_latexrun//': Traceback (most recent call last):
	File "/home/cirrus/.cache/bazel/_bazel_cirrus/b3ae12dd079012e10ed112b1996c540f/external/bazel_tools/tools/build_defs/repo/http.bzl", line 55
		patch(ctx)
	File "/home/cirrus/.cache/bazel/_bazel_cirrus/b3ae12dd079012e10ed112b1996c540f/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 79, in patch
		fail(("Error applying patch %s:\n%s%s...)))
Error applying patch @bazel_latex//:patches/latexrun-force-colors:
bash: patch: command not found

sha256 value availability when releasing

Dear developer,
What is the sha256sum value for each release?
Could it be available either in the release description or the release file which is needed in the WORKSPACE file?

Best regards

Support for biber/biblatex

Hello! Enjoying the bazel support thus far :)

I'm trying to use biblatex but having some trouble so far. I'm not very familiar with bazel, so I'm not sure how to run a biber command in between. For example, I have the following added to packages/BUILD.bazel:

latex_package(
    name = "biblatex",
    srcs = [
        "@texlive_texmf__texmf-dist__tex__latex__biblatex",
        "@texlive_texmf__texmf-dist__tex__latex__logreq",
        "@texlive_texmf__texmf-dist__tex__latex__oberdiek",
        ":etoolbox",
        ":keyval",
        ":url",
        "biblatex.bib",
    ],
    tests = ["biblatex_test.tex"],
)

Then biblatex_test.tex simply has:

\documentclass{report}
\usepackage{biblatex}
\addbibresource{biblatex.bib}
\begin{document}
Check out my citation \cite{my_ref}
\printbibliography
\end{document}

If I run this locally, I'm able to build the PDF just fine but if I run bazel run //packages:biblatex_biblatex_test.tex_view, I get the following error code:

ERROR: /home/kyle/code/bazel-latex/packages/BUILD.bazel:96:1: LuaLatex packages/biblatex_biblatex_test.tex.pdf failed (Exit 1) python failed: error executing command python external/bazel_latex/run_lualatex.py external/texlive_bin__x86_64-linux/kpsewhich external/texlive_bin__x86_64-linux/luatex external/bazel_latex_latexrun/latexrun biblatex_biblatex_test.tex ... (remaining 2 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
packages/biblatex_test.tex:5: warning: Citation 'my_ref' on page 1 undefined
packages/biblatex_test.tex:6: warning: Empty bibliography
packages/biblatex_test.tex: warning: [biblatex] Please (re)run Biber on the file: biblatex_biblatex_test.tex and rerun LaTeX afterwards
biblatex_biblatex_test.tex.aux: error: no \citation commands
biblatex_biblatex_test.tex.aux: error: no \bibdata command
biblatex_biblatex_test.tex.aux: error: no \bibstyle command
Target //packages:biblatex_biblatex_test.tex_view failed to build
Use --verbose_failures to see the command lines of failed build steps.

Any thoughts/advice on how to integrate Biber with bazel-latex?

Support for TrueType fonts?

Not quite sure if this is the right place to ask.

I'm currently trying to build a document in which I use Carlito as main font.

\usepackage{fontspec}

\setmainfont{Carlito}

I used to build this document with lualatex installed on my local system and recently switched to using bazel-latex. The switch went perfectly fine.

Today I attempted to build the same repository (updated to add bazel-toolchains) with bazel-buildbarn. When doing this, the build exists with an error.

ERROR: /network/nas/documents/work/cv/BUILD.bazel:3:1: LuaLatex curriculum_vitae.pdf failed (Exit 1)
cv.tex:9: error: [fontspec] "font-not-found"
      at \setmainfont{Carlito}
cv.tex:9: error: [fontspec] "font-not-found"
      at \setmainfont{Carlito}
cv.tex:9: error: [fontspec] "font-not-found"
      at \setmainfont{Carlito}
cv.tex:9: error: Font \TU/Carlito(0)/m/n/10=Carlito:mode=node;+tlig; at 10pt not loadable: metric data not found or bad
      at <to be read again>
    from \setmainfont{Carlito}

I attempted to solve the problem by adding the relevant *.ttf files to srcs, but this doesn't make a difference.

Is the use of custom fonts currently supported by bazel-latex?

Updating TexLive

Hi,

I’m considering using this repository for a project but I’m concerned that I’ll be forced to use TexLive 2019 forevermore, or until the bazel-latex developers decide to update.

May I ask if there is a process for users of bazel-latex to use a different (newer) version of TexLive?

Thanks

The example fails to build on Linux: `latexrun` `IndexError`

When I attempt to run bazel build //example/... on my Linux system (specifically, Fedora 34 and Bazel v4.0.0), I consistently get an error like the following:

ERROR: /home/dwtj/Projects/bazel-latex/example/BUILD.bazel:3:15: LuaLatex example/my_report.pdf failed: (Exit 1): run_lualatex failed: error executing command bazel-out/host/bin/run_lualatex external/texlive_bin__x86_64-linux/kpsewhich external/texlive_bin__x86_64-linux/luatex external/texlive_bin__x86_64-linux/bibtex external/texlive_bin__x86_64-linux/biber ... (remaining 6 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox run_lualatex failed: error executing command bazel-out/host/bin/run_lualatex external/texlive_bin__x86_64-linux/kpsewhich external/texlive_bin__x86_64-linux/luatex external/texlive_bin__x86_64-linux/bibtex external/texlive_bin__x86_64-linux/biber ... (remaining 6 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
Traceback (most recent call last):
  File "/home/dwtj/.cache/bazel/_bazel_dwtj/01719a99d816f1177918d0383df58452/sandbox/linux-sandbox/18/execroot/bazel_latex/external/bazel_latex_latexrun/latexrun", line 1982, in <module>
    main()
  File "/home/dwtj/.cache/bazel/_bazel_dwtj/01719a99d816f1S177918d0383df58452/sandbox/linux-sandbox/18/execroot/bazel_latex/external/bazel_latex_latexrun/latexrun", line 169, in main
    stable = run_tasks(tasks, args.max_iterations)
  File "/home/dwtj/.cache/bazel/_bazel_dwtj/01719a99d816f1177918d0383df58452/sandbox/linux-sandbox/18/execroot/bazel_latex/external/bazel_latex_latexrun/latexrun", line 558, in run_tasks
    task.run()
  File "/home/dwtj/.cache/bazel/_bazel_dwtj/01719a99d816f1177918d0383df58452/sandbox/linux-sandbox/18/execroot/bazel_latex/external/bazel_latex_latexrun/latexrun", line 655, in run
    result = self._execute()
  File "/home/dwtj/.cache/bazel/_bazel_dwtj/01719a99d816f1177918d0383df58452/sandbox/linux-sandbox/18/execroot/bazel_latex/external/bazel_latex_latexrun/latexrun", line 1657, in _execute
    inputs, auxnames, outbase = self.__parse_inputs(stdout, cwd, env)
  File "/home/dwtj/.cache/bazel/_bazel_dwtj/01719a99d816f1177918d0383df58452/sandbox/linux-sandbox/18/execroot/bazel_latex/external/bazel_latex_latexrun/latexrun", line 1751, in __parse_inputs
    outbase = auxnames[0][:-4]
IndexError: list index out of range
----------------
Note: The failure of target //:run_lualatex (with exit code 1) may have been caused by the fact that it is running under Python 3 instead of Python 2. Examine the error to determine if that appears to be the problem. Since this target is built in the host configuration, the only way to change its version is to set --host_force_python=PY2, which affects the entire build.

If this error started occurring in Bazel 0.27 and later, it may be because the Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a Python 2 and Python 3 interpreter, respectively. See https://github.com/bazelbuild/bazel/issues/7899 for more information.
----------------

However, I do not get this error when I build the project on my macOS machine (specifically, macOS 11.3.1 and Bazel 4.0.0).

Clearly, the error is coming from the latexrun script's __parse_inputs() function. The cause is that this expression indexes into the empty list.

(Note: the hint about Python 2/3 seems to be a false lead, since Linux fails regardless of Python version and macOS succeeds regardless of version.)

By adding an additional latexrun patch, I found that when __parse_inputs() is run:

  • outbase is set to None on Linux
  • outbase is set to "my_report" on macOS.

Thus, on macOS, the offending line of code isn't being hit. So no error, and the build succeeds.

My hunch is that this problem might arise from differences between Bazel's sandboxing strategies on these two platforms. But just using the Bazel option --spawn_strategy=local doesn't fix anything, so maybe not.

I know next to nothing about LaTeX compilation, so I'll leave it to others to further diagnose the issue.

mtheme package

Can someone please add mtheme to the package archive? Or can we add a way to use packages that aren't in this repo?

Failing to build with long filenames

While adding support to https://ctan.org/pkg/beamertheme-metropolis, I ended up having a weird issue when building the test:

Output written on beamertheme_metrop_beamertheme_metropolis_test.tex.pdf (3 pag
es, 11581 bytes).
Transcript written on beamertheme_metrop_beamertheme_metropolis_test.tex.log.

failed to extract output name from latex log

Note the name of the file: beamertheme_metrop_beamertheme_metropolis_test.tex.pdf. If I remove one letter, it works just fine. If I add more, it keeps failing. My guess is that part of lualatex uses a regex to match that output name, based on matching a line ending with \d+ page, which starts failing here.

Is it something that should:

  1. Be documented?
  2. Be avoided, by enforcing smaller file names?

What pattern should we use for test cases having too long of a name?

\include{} doesn't work

Thanks for making this rule.

I've encountered a problem on a basic document though: \include{} doesn't do anything.

Exemple
manual.tex

\documentclass{article}
\begin{document}
Generated by Bazel
\include{hello}
\include{wtf}
\end{document}

hello.tex

Hello world

BUILD

latex_document(
    name = "manual",
    srcs = [
        "hello.tex",
        ],
    main = "manual.tex",
)

The PDF is generated with no error but

  • hello.tex isn't included
  • wtf.tex which doesn't exist doesn't raise an error in the \include{} statement

latexrun file is not executable when building

The bazel latex build was failing because the latexrun_file was not executable, resulting in a traceback like this:

Traceback (most recent call last):
  File "external/bazel_latex/run_lualatex.py", line 62, in <module>
    env=env,
  File "/usr/lib64/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 13] Permission denied
Target //intro_cpp:syllabus failed to build

The latexrun_file is not executable and expects that python3 be put in front it, though it has a #!/usr/bin/env python3 shebang at the top of the file. I've fixed this locally by appending a python3 command in front of the latexrun_file argument in the subprocess.call(...). Opening this issue to hopefully get this fixed in the code itself.

Support for tikz-3dplot

Add support for tikz-3dplot

I tried the following:

packages/BUILD.bazel extended with:

latex_package(
    name = "tikz-3dplot",
    srcs = [":pgf"],
    tests = ["tikz-3dplot_test.tex"],
)

tikz-3dplot_test.tex:

\documentclass{report}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{60}{110}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
%draw the main coordinate system axes
\draw[thick,->] (0,0,0) -- (-1,0,0) node[anchor=south]{$z+$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$x+$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$y+$};
\end{tikzpicture}
\end{tikzpicture}
\end{document}

No idea what else is needed to get it working

Setting spawn_strategy=local breaks LuaLatex

When running Bazel with --spawn_startegy=local lualatex fails to find lualatex.fls

$bazel build --spawn_strategy=local ...                                                                                                                                  
INFO: Analyzed 2 targets (0 packages loaded, 0 targets configured).                                                                                                         
INFO: Found 2 targets...                                                                                                                                                    
ERROR: /home/cjmakes/projects/bug/BUILD:3:1: LuaLatex main.pdf failed (Exit 1)                                                                                             
failed to open file recorder output: [Errno 2] No such file or directory: 'lualatex.fls'                                                                                    
There were errors; output not updated                                                                                                                                       
                                                                                                                                                                            
INFO: Elapsed time: 0.270s, Critical Path: 0.20s                                                                                                                            
INFO: 0 processes.                                                                                                                                                          
FAILED: Build did NOT complete successfully                                                                                                                                  

$bazel build --spawn_strategy=sandboxed ...                                                                                                                              
INFO: Analyzed 2 targets (0 packages loaded, 0 targets configured).                                                                                                         
INFO: Found 2 targets...                                                                                                                                                    
INFO: Elapsed time: 2.548s, Critical Path: 2.49s                                                                                                                            
INFO: 1 process: 1 linux-sandbox.                                                                                                                                           
INFO: Build completed successfully, 2 total actions           

Tested in official bazel docker container versions .27 and .28.1

PoB Repo: https://github.com/cjmakes/bazel-latex-bug

Add buildifier to pipeline

https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md#buildifier

https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md#setup-and-usage-via-bazel-not-supported-on-windows

Also, consider adding github actions,
both pipelines could live in parallell and reference some common shell script, containing the commands to execute in the pipeline.

e.g.

ci.sh:
bazel build //buildifier
find -iname "*.bzl" | xargs bazel run //:buildifier -- --lint=warn
bazel build //example/:all
bazel build //packages/:all

Printing glossaries

Hey there,

I am currently trying to switch my latex-thesis to Bazel. In order to add the glossaries with the \printglossary command, you have to invoke the makeglossaries command after compiling your tex files and recompile everything again afterward.
Any idea how to incorporate this with bazel-latex or is there a trick?

The compilation process runs fine when I use it the same way as shown in the test, but the glossary does not show up.

Not quite sure if this belongs here. Feel free to close this issue in case it does not :)

Greets! Thanks for the awesome work

xelatex

Is it possible to use xelatex? I see lualatex, but it seems to be really slow for me.

Use Travis CI

We should ensure that the build is always green. Continuous Integration with Travis CI is a good way to do this. We should integrate with Travis CI.

Problem on OS X with Bazel 0.15.2

First of all, thank you for providing this extension!

I ran into a problem trying this out on OS X, with Bazel 0.15.2.

$> bazel run :my_report_view
Starting local Bazel server and connecting to it...
.............
INFO: Analysed target //:my_report_view (47 packages loaded).
INFO: Found 1 target...
ERROR: /Users/mtsgrd/c/resume/BUILD:3:1: SkylarkAction my_report.pdf failed (Exit 1)
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex)
 restricted \write18 enabled.

kpathsea: Running mktexfmt pdflatex.fmt
/private/var/tmp/_bazel_mtsgrd/0d605fe67c66d81e0a753bdfcbb497fc/sandbox/darwin-sandbox/2/execroot/__main__/bin/kpsewhich: /private/var/tmp/_bazel_mtsgrd/0d605fe67c66d81e0a753bdfcbb497fc/sandbox/darwin-sandbox/2/execroot/__main__/bin/kpsewhich: cannot execute binary file
/private/var/tmp/_bazel_mtsgrd/0d605fe67c66d81e0a753bdfcbb497fc/sandbox/darwin-sandbox/2/execroot/__main__/bin/mktexfmt: kpsewhich -var-value=TEXMFROOT failed, aborting early.
BEGIN failed--compilation aborted at /private/var/tmp/_bazel_mtsgrd/0d605fe67c66d81e0a753bdfcbb497fc/sandbox/darwin-sandbox/2/execroot/__main__/bin/mktexfmt line 25.
I can't find the format file `pdflatex.fmt'!
Target //:my_report_view failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 18.296s, Critical Path: 0.62s
INFO: 1 process: 1 darwin-sandbox.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

Any idea what's going on?

Switch CI to GitHub Actions

  • Set up GitHub Actions (#91)
  • Either define a Windows toolchain or remove Windows from the matrix (#94, #95)
  • Fix the cache directories - apparently the cache directories aren't created and GitHub Actions isn't saving anything
  • Figure out why the example targets are building on macOS and locally but not on Ubuntu on CI
  • Clean-up Cirrus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.