Skip to content

Instantly share code, notes, and snippets.

View bpj's full-sized avatar

Benct Philip Jonsson bpj

View GitHub Profile
@bpj
bpj / pandoc-newpage.pl
Last active January 12, 2022 17:10
Pandoc filter which converts LaTeX \newpage commands into appropriate pagebreak markup for other formats.
#!/usr/bin/env perl
# Pandoc filter which converts paragraps containing only the LaTeX
# `\newpage` or `\pagebreak` command into appropriate pagebreak markup
# for other formats.
#
# You will need perl version 5.10.1 or higher <https://www.perl.org/get.html>
# (Strawberry Perl recommended on Windows!)
# and a module installer <http://www.cpan.org/modules/INSTALL.html>
# and the Pandoc::Elements module version 0.33 or higher
# Autogenerated LaTeX-related files
*.aux # An auxiliary file that saves information for the creation of ToC, references, indices, bibliographies and other things like that. It is reread in the next compiling to create the ToC, references etc.
*.toc # An auxiliary file that stores the Table of Contents, read in on subsequent runs to create the actual ToC.
*.log # Stors all messages of the compilation, like errors and warnings. It’s used by most Editors / LaTeX IDEs to show the errors in you document.
*.nav # contains the information needed for the navigation bar hyperlinks.
*.vrb # will contain the verbatim material when fragile (containing verbatim material) frames.
*.snm # will contain information that will be used by \pgfimage to include actual slides when using the beamerarticle package.
*.tuc # Data stored for multiple passes, ToC, etc.
# (La)TeX:
# Lists:
@bpj
bpj / hyperendnotes.sty
Created December 15, 2016 19:52
Load after endnotes, after hyperref to make endnote markers hyperlinks. I didn't write this. I just put it here to have a convenient place to grab it!
%%% hyperendnotes.sty
\makeatletter
\newif\ifenotelinks
\newcounter{Hendnote}
% Redefining portions of endnotes-package:
\let\savedhref\href
\let\savedurl\url
\def\endnotemark{%
\@ifnextchar[\@xendnotemark{%
\stepcounter{endnote}%
@bpj
bpj / html-self-links.pl
Created November 23, 2016 23:15
Generate self links in headings with HTML or Pandoc filter
@bpj
bpj / steal-attrs.pl
Last active November 13, 2016 20:15
steal-attrs.pl - Let HTML elements steal their ancestor's attributes
#!/usr/bin/env perl
=encoding UTF-8
=head1 NAME
steal-attrs.pl - Let HTML elements steal their ancestor's attributes.
=head1 VERSION
@bpj
bpj / pandoc-html-only.pl
Last active October 13, 2016 09:43
Pandoc filter to filter out stuff unless the output format is html/html4/html5
#!/usr/bin/env perl
# exclude spans/divs marked html/html4/html5 unless output format is html/html4/html5
use utf8;
use autodie 2.26;
use 5.010001;
use strict;
use warnings;
use warnings qw(FATAL utf8);
@bpj
bpj / pandoc-sf-sc.py
Last active May 23, 2016 17:19
Pandoc filter which fakes sans and small-caps syntax by overloading link syntax
#!/usr/bin/env python
"""
Pandoc filter which fakes sans and small-caps syntax through
overloading link syntax. It wraps the text of links with the
pseudo-urls ``-sf`` and ``-sc`` in HTML spans with the classes
"sans" and "small-caps" or LaTeX ``\textsf{...}`` and ``\textsc{...}``
commands::
[this is sans text](-sf)
@bpj
bpj / pandoc-incl-excl.py
Last active May 18, 2016 20:38
Pandoc filter which keeps/removes divs/spans which have some class
#!/usr/bin/env python
"""
Pandoc filter which removes divs and/or spans according to whether they
have certain classes which are listed in metadata or not. There are four
relevant metadata entries:
- incl_div
- excl_div
- incl_span
- excl_span
Moved to https://github.com/bpj/perlsubst.vim
@bpj
bpj / pandoc-code2raw.py
Last active October 30, 2016 23:34
Pandoc filter to insert arbitrary raw output markup as Code/CodeBlocks with an attribute raw=<outputformat>.
#!/usr/bin/env python
r"""Pandoc filter to insert arbitrary raw output markup
as Code/CodeBlocks with an attribute raw=<outputformat>.
Especially useful for inserting LaTeX code which pandoc will
otherwise mangle:
````{raw=latex}
\let\Begin\begin