aboutsummaryrefslogtreecommitdiff
path: root/_make/quarto.mk
blob: 5e2fe8ab8c945da37be230b63ee712641d712ccc (plain)
  1. # Make snippet for rendering Quarto documents
  2. #
  3. # Copyright 2024, Jonas Smedegaard <dr@jones.dk>
  4. # SPDX-License-Identifier: GPL-3+
  5. #
  6. # Setup:
  7. # In main Makefile...
  8. # * set variable DOCUMENTS
  9. # * set variable DOCUMENT_APPENDIX_REGEX if needed
  10. # * include this make snippet
  11. #
  12. # Dependencies:
  13. # * quarto <https://quarto.org/>
  14. # * perl v5.10.1 or newer
  15. #
  16. # Suggestions:
  17. # * glow <https://github.com/charmbracelet/glow>
  18. # * bat <https://github.com/sharkdp/bat>, with executable named "batcat"
  19. # list of relative paths to directories,
  20. # each containing an index.qmd file.
  21. #DOCUMENTS = \
  22. # main_paper \
  23. # promo_article \
  24. # research/deep/superconductors
  25. # research/deep/fringe
  26. # regular expressions anchored at the beginning of a single line,
  27. # to match the beginning of content in document to omit from counting
  28. DOCUMENT_APPENDIX_REGEX ?= Appendix\\b
  29. DOCUMENT_BIBLIOGRAPHY_REGEX ?= Bibliography\\b
  30. # pick as decent a Markdown pager as locally available
  31. _which = $(shell command -v $1 >/dev/null 2>&1 && echo $1 $2)
  32. CAT ?= $(strip $(or \
  33. $(call _which,glow,--pager),\
  34. $(call _which,batcat,--language markdown),\
  35. cat))
  36. PDF_DOCUMENTS ?= $(patsubst %.qmd,_site/%.pdf,$(DOCUMENTS))
  37. $(DOCUMENTS:%=doc-render-%): doc-render-%: _site/%.pdf
  38. _site/%.pdf: %.qmd
  39. quarto render $<
  40. $(DOCUMENTS:%=doc-screening-of-%): doc-screening-of-%: %.qmd
  41. QUARTO_LOG_LEVEL=quiet \
  42. quarto render $< --to markdown --output - | $(CAT)
  43. # count all characters except horisontal rulers,
  44. # until appendices
  45. $(DOCUMENTS:%=doc-charcount-of-%): doc-charcount-of-%: %.qmd
  46. QUARTO_LOG_LEVEL=quiet \
  47. quarto render $< --to plain --columns=9999 --output - \
  48. | perl -nsE 'next if /^-*$$/; $$done += /^$$re/; $$chars += length unless $$done; END { say $$chars }' \
  49. -- -re="$(DOCUMENT_APPENDIX_REGEX)"
  50. # count all characters except horisontal rulers,
  51. # until bibliography,
  52. # divide by 2400 and floor the result
  53. $(DOCUMENTS:%=doc-pagecount-of-%): doc-pagecount-of-%: %.qmd
  54. QUARTO_LOG_LEVEL=quiet \
  55. quarto render $< --to plain --columns=9999 --output - \
  56. | perl -nsE 'next if /^-*$$/; $$done += /^$$re/; $$chars += length unless $$done; END { say $$chars }' \
  57. -- -re="$(DOCUMENT_BIBLIOGRAPHY_REGEX)" \
  58. | perl -nE 'say int($$_ / 2400)'
  59. .PHONY: $(DOCUMENTS:%=doc-render-%) $(DOCUMENTS:%=doc-screening-of-%) \
  60. $(DOCUMENTS:%=doc-charcount-of-%) $(DOCUMENTS:%=doc-pagecount-of-%)