aboutsummaryrefslogtreecommitdiff
path: root/_make/quarto.mk
blob: 63ad6176284f30dcc9c932ba83ba9df795cc56d7 (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. # * bat <https://github.com/sharkdp/bat>, with executable named "batcat"
  15. # * perl v5.10.1 or newer
  16. # list of relative paths to directories,
  17. # each containing an index.qmd file.
  18. #DOCUMENTS = \
  19. # main_paper \
  20. # promo_article \
  21. # research/deep/superconductors
  22. # research/deep/fringe
  23. # regular expressions anchored at the beginning of a single line,
  24. # to match the beginning of content in document to omit from counting
  25. DOCUMENT_APPENDIX_REGEX ?= Appendix\\b
  26. DOCUMENT_BIBLIOGRAPHY_REGEX ?= Bibliography\\b
  27. $(DOCUMENTS:%=doc-render-%): doc-render-%: %.qmd
  28. quarto render $<
  29. $(DOCUMENTS:%=doc-screening-of-%): doc-screening-of-%: %.qmd
  30. QUARTO_LOG_LEVEL=quiet \
  31. quarto render $< --to markdown --output - | batcat --file-name index.qmd --language markdown
  32. # count all characters except horisontal rulers,
  33. # until appendices
  34. $(DOCUMENTS:%=doc-charcount-of-%): doc-charcount-of-%: %.qmd
  35. QUARTO_LOG_LEVEL=quiet \
  36. quarto render $< --to plain --columns=9999 --output - \
  37. | perl -nsE 'next if /^-*$$/; $$done += /^$$re/; $$chars += length unless $$done; END { say $$chars }' \
  38. -- -re="$(DOCUMENT_APPENDIX_REGEX)"
  39. # count all characters except horisontal rulers,
  40. # until bibliography,
  41. # divide by 2400 and floor the result
  42. $(DOCUMENTS:%=doc-pagecount-of-%): doc-pagecount-of-%: %.qmd
  43. QUARTO_LOG_LEVEL=quiet \
  44. quarto render $< --to plain --columns=9999 --output - \
  45. | perl -nsE 'next if /^-*$$/; $$done += /^$$re/; $$chars += length unless $$done; END { say $$chars }' \
  46. -- -re="$(DOCUMENT_BIBLIOGRAPHY_REGEX)" \
  47. | perl -nE 'say int($$_ / 2400)'
  48. .PHONY: $(DOCUMENTS:%=doc-render-%) $(DOCUMENTS:%=doc-screening-of-%) \
  49. $(DOCUMENTS:%=doc-charcount-of-%) $(DOCUMENTS:%=doc-pagecount-of-%)