1

I have got a folder with many lyx files. What makefile will automatically build abc.pdf from abc.lyx? I would prefer a pattern so that I can address each pdf target separately. I have not found a working example online.

  • I'm not sure what you mean by "address each pdf target separately". Do you mean run a different LyX command for each? Or run different commands in addition? – scottkosty Jan 14 at 16:30
  • As far as I know, you define rules that depend on the file extension. Like, for each .lyx file there exists a corresponding .pdf target. By "address each pdf target separately" I just avoiding bash for-each loops that could do the job similarly. – shuhalo Jan 15 at 0:53
0

Here is a complete Makefile:

abc.pdf: abc.lyx

.SUFFIXES: .lyx .pdf
# if lyx command fails, remove pdf
.lyx.pdf:
    lyx -e pdf4 "$<"
    ret_lyx=$$? ;\
    if [ "$$ret_lyx" != "0" ]; then \
      [ -f "$*.pdf" ] && rm "$*.pdf" ;\
    fi ;\
    exit $$ret_lyx

To test it out, put the above in a file "Makefile" and put that in a directory with a file "abc.lyx" and run "make". The below output gives an idea of how it works:

$ ls
abc.lyx  Makefile
$ make
lyx -e pdf4 "abc.lyx"
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./abc.tex
LaTeX2e <2019-10-01> patch level 1

ret_lyx=$? ;\
if [ "$ret_lyx" != "0" ]; then \
  [ -f "abc.pdf" ] && rm "abc.pdf" ;\
fi ;\
exit $ret_lyx
$ make
make: 'abc.pdf' is up to date.
$ touch abc.lyx 
$ make
lyx -e pdf4 "abc.lyx"
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./abc.tex
LaTeX2e <2019-10-01> patch level 1

ret_lyx=$? ;\
if [ "$ret_lyx" != "0" ]; then \
  [ -f "abc.pdf" ] && rm "abc.pdf" ;\
fi ;\
exit $ret_lyx
$ 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.