First off, I am very new to bazel. I am one of those people who always want to transition, but every time I try I seem to hit a fairly steep learning curve and sadly go back to make because in the end of the day there is a limit to how much I can spend my workdays mucking around with a build system.
So I was going to type up some documentation today and thought, "hey, I was about to write a makefile for this, the project is stupidly simple, why not use this as a starting point for using bazel". As it is latex, I will also get a feel for how bazel work outside of the predefined rules. Because that has to me always been a huge issue. If you want to compile a simple C++ program you look at the tutorial, and as long as your problem can be accomplished by the steps described there, it is roses all the way. However, the moment I want to customize anything, the whole thing falls apart for me, and digging through the documentation for a couple of hours doesn't really seem to help. E.g. I needed to turn off -std=c++11 for a program I was working on, and getting bazel to do that took me multiple hours.
Sorry about the long setup, it is not a rant, I really want to learn, it can just feel a bit daunting at times. Here is my problem:
I have a folder with a .tex file in it. I want to compile this with either pdflatex, xelatex or use latexmk, anything to create a .pdf file. My first though was to use a genrule to do it, but while I was at it, I thought I might as well define a macro. So in my root folder I define a file "buildutils.bzl" which contains the following:
def _replace_extension(input_str, ext_from, ext_to):
return input_str.split(ext_from)[0] + ext_to
def latex_pdf(name, src):
native.genrule(
name = name,
srcs = [src],
outs = [_replace_extension(src, ".tex", ".pdf")],
cmd = "latexmk -pdf -xelatex $(location " + src + ")"
)
Simple enough for now I though. No need for anything fancy like checking that src really is a .tex file etcetc. I'm sure you see the mistake immediately, but this is my attempt. Then in the folder my .tex file is I have this BUILD file
load("//:buildutils.bzl", "latex_pdf")
latex_pdf(
name = "documentation",
src = "documentation.tex"
)
Trying to compile this does not work, it complains that it never produced the pdf file. The reason for this I assume is that the files are produced in the wrong folders. This is because latexmk unfortunately produces its output in the folder it is called from. Not that much I can do about that. latexmk does provide a "-cd" option which it claims make it output relative to the source file, but that didn't work for reasons unknown to me.
So my question is this. How do I proceed? I would somehow need to either cd to the folder before I call the command, something along:
cmd = "cd $(dir " + src + ") && latexmk -pdf -xelatex $(location " + src + ")"
Or find a way for the macro to compute the directory, and pass that as a parameter to latexmk via the "-outdir" option.
Besides this I do have some questions regarding where bazel stores things. I understand that they are placed in cashe directories and symlinked in place, which is fine. However, latex produces quite a bit of auxillary files, and these are used in latex compilations to speed up the build process. Will these be available to pdflatex/xelatex/latexmk on later builds? These e.g. help with cross-referencing, as well as making it so that you only have to build separate sections if they are changed etcetc.
Do you have any guidelines for going about adapting bazel to work with tex? Also, how e.g. would one get it to work so that if one .tex file produces a figure that is needed by another tex file? Maybe it "just works" whenever you get the basics working.
Sorry for the long question.
Cheers,
Jonas
--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/aaf008dd-3b79-4269-828c-01603bb3e235%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I hope you're doing great. Say hi to some of the others in Munich!
Op maandag 24 juli 2017 13:19:07 UTC+2 schreef Klaus Aehlig:
> I attach the relevant fragment of my personal bazel rules.
Thanks for publishing this. Very useful!
At my current employer we also want to have some basic library/inheritance functionality for LaTeX, so that we can easily reuse templates for requirements specification/design/testing results documents. I've just published our fork of your rules on our company's GitHub page:
https://github.com/ProdriveTechnologies/bazel-latex
Ed