diff --git a/Makefile b/Makefile index 8d4dbbf..1ac8b84 100755 --- a/Makefile +++ b/Makefile @@ -8,22 +8,24 @@ help: %.html: %.markdown src/template-*.html src/rules-html-pre.sed src/rules-html-post.sed @echo @echo "Build HTML: $*.html" - n="$*"; python3 src/temp_prepare.py src/template-$${n%%-*}.html $*.markdown $*.html.1.tmp - sed -f src/rules-html-pre.sed $*.markdown.tmp | pandoc -t html -o $*.html.2.tmp + sed -f src/rules-html-pre.sed $*.markdown > $*.sed.md + n="$*"; python3 src/temp_prepare.py src/template-$${n%%-*}.html $*.sed.md > $*.html.1.tmp + pandoc -t html -o $*.html.2.tmp -f markdown $*.sed.md.tmp sed -f src/rules-html-post.sed $*.html.2.tmp > $*.html python3 src/temp_combine.py $*.html.1.tmp $*.html - rm -f $*.markdown.tmp $*.html.1.tmp $*.html.2.tmp + rm -f $*.sed.md $*.sed.md.tmp $*.html.1.tmp $*.html.2.tmp cp $*.html bin/ %.tex: %.markdown src/template-*.tex src/rules-tex-pre.sed src/rules-tex-post.sed @echo @echo "Build TEX: $*.tex" - n="$*"; python3 src/temp_prepare.py src/template-$${n%%-*}.tex $*.markdown $*.tex.1.tmp + sed -f src/rules-tex-pre.sed $*.markdown > $*.sed.md + n="$*"; python3 src/temp_prepare.py src/template-$${n%%-*}.tex $*.sed.md > $*.tex.1.tmp # heading shift needed because tufte doesnt have subsubsection - sed -f src/rules-tex-pre.sed $*.markdown.tmp | pandoc --shift-heading-level-by=-1 -t latex -o $*.tex.2.tmp + pandoc --shift-heading-level-by=-1 -t latex -o $*.tex.2.tmp -f markdown $*.sed.md.tmp sed -f src/rules-tex-post.sed $*.tex.2.tmp > $*.tex python3 src/temp_combine.py $*.tex.1.tmp $*.tex - rm -f $*.markdown.tmp $*.tex.1.tmp $*.tex.2.tmp + rm -f $*.sed.md $*.sed.md.tmp $*.tex.1.tmp $*.tex.2.tmp %.pdf: %.tex @echo diff --git a/README.md b/README.md index b3b1500..8615038 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,36 @@ Included in the package: - Font [Cochineal](https://www.ctan.org/pkg/cochineal), by Michael Sharpe - Font [Roboto](https://github.com/googlefonts/roboto), by Christian Robertson - Font [Iosevka](https://github.com/be5invis/Iosevka), by Belleve Invis +- Font [Piazzolla](https://github.com/huertatipografica/piazzolla), by Juan Pablo del Peral ## Usage The format is mostly markdown, except for these modifications: -- Use `\,` to insert a non-breaking thin-space. +- Whitespace + - Use `\,` to insert a non-breaking thin-space. + - Use `\~` or the actual character to insert a normal-width non-breaking space (unicode nbsp in macOS: `Alt + Space`, Linux: `???`, Windows: `???`). + - Use `\newpage` to start a new page in latex (which is ignored in html) -- To insert a normal-width non-breaking space use `\~` or the actual character (macOS: `Alt + Space`, Linux: `???`, Windows: `???`). +- Use `@== CONTENT ==@` to create a margin element; Text or image or whatever. + - multi-line content allowed. + - the prefix `@=latex=` will display its content in pdf only. There is no html-prefix equivalent. -- Use `\newpage` to start a new page in latex (which is ignored in html) +- Use `####` to create paragraph like sections. These sections are displayed in the margin. Like an index for quick reference. In mobile html they are normal `h4` headings. + - Of course `#`, `##`, and `###` are translated to `h1` to `h3` headings -- It supports the latex `\begin{description}` environment by using the html equivalent `
` +- You can add a reference-id to a title by adding `{#label}` after the title, e.g., `## Title {#title}` + - other than that, all titles have implicit labels where spaces are replaced with dashes `My Title` becomes `my-title` + - btw., you can also add classes this way `{.fullwidth}` + - Use normal markdown syntax `[name](#ref)` to link to a section (works in both, html and latex) + +- Use `
` to create definition lists. This will be translated to a latex `\begin{description}` environment. + + +## Templating + +- The file prefix, e.g. `en`, is the template file identifier. This can be used for multi-language generation or different types of webpages. - The header always begins and ends with a line of at least five colons `:::::` - Each line inside the header has the format `KEY: VALUE` @@ -44,37 +61,7 @@ The format is mostly markdown, except for these modifications: - Each ML-variable begins with ` KEY : @@@ ` and ends with a line of just three at-signs (regex: `^@@@$`). No whitespace allowed. - multi-line variables may contain a line of colons (the header terminator is ignored here) -- You can add a reference to a title by adding `{#label}` after the title, e.g., `## Title {#title}` - - other than that, all titles have implicit labels where spaces are replaced with dashes `My Title` becomes `my-title` - - btw., you can also add classes this way `{.fullwidth}` - -- The file prefix, e.g. `en`, is the template file identifier. This can be used for multi-language generation or different types of webpages. - -- Use `@== content ==@` to place something in the border margin. - - multi-line content is allowed. - - the prefix `@=latex=` will display something in the pdf but not in html. (there is no equivalent for html-only) - ## Limitations This script has not been tested on Linux or Windows. However, Linux should work fine ... in theory. - -### Known Issues - -__#1__: If using URLs ins the margin, adding a newline before the href will add an unwanted space. e.g.: - -``` -@== -[multi line, super long name desc!](multi-line-url) -==@ -``` - -will become: - -``` -| multi line, -| super long -| name desc! -``` - -Fix for __#1__: place the beginning of the url on the same line `@==[]()...` (does not have to be closed on the same line) diff --git a/bin/custom.css b/bin/custom.css old mode 100644 new mode 100755 index aa31b02..9b9bbe6 --- a/bin/custom.css +++ b/bin/custom.css @@ -1,43 +1,89 @@ -.button { - border: 2px solid #ff5050; - color: #ff5050; - background-color: #fff; - padding: 16px 32px; - font-size: 16px; - font-weight: bold; - margin: 4px 2px; - cursor: pointer; -} - -.button:hover { - color: #fff; - background-color: #ff5050; +@font-face { font-family: 'Roboto'; src: url(fonts/Roboto-Regular.otf); } /* only h1-6, thus no italic */ +@font-face { font-family: 'Piazzolla'; src: url(fonts/Piazzolla.ttf); } +@font-face { font-family: 'Piazzolla'; font-style: italic; src: url(fonts/Piazzolla-Italic.ttf); } + +body { + font-family: Piazzolla, Helvetica Neue, sans-serif; + font-weight: 400; +} +b,strong { font-weight: 600; } +h1,h2,h3,h4,h5,h6,.topnav { + font-family: Roboto, Helvetica Neue, sans-serif; +} +#subtitle { margin-top: inherit; } +@media (prefers-color-scheme: dark) { + body { background: #17110E; color: #DDD; font-weight: 500; } + b, strong { font-weight: 600; color: #FFF; } } +/* Quick-jump to section navigation */ div.topnav { - position: sticky; - top: 0; + color:grey; z-index: 1; background-color: white; overflow: hidden; width: max-content; max-width: 100%; } - .topnav a { float: left; - color:grey; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 16px; display: block; } - .topnav a:hover { background-color: whitesmoke; color: black; } +@media (prefers-color-scheme: dark) { + div.topnav { background-color: #372F2C; color: #DDD; } +} + +/* Back-to-top button */ +.button { + border: 2px solid #ff5050; + color: #ff5050; + background-color: #ffffff; + align-self: baseline; + padding: 16px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + font-weight: bold; + margin: 4px 2px; + transition-duration: 0.4s; + cursor: pointer; + position: fixed; + bottom: 1em; +} +.button:hover { + color: #ffffff; + transition-timing-function: ease-in; + -webkit-backface-visibility: hidden; + backface-visibility: hidden; + background-color: #ff5050; +} + +/* Margin-Sections */ +p + .h4-spacer { + margin-top: 2.2rem; +} +h4 { + display: none; + font-size: 1.4em; + margin-bottom: 1rem; +} +h4 + p { margin-top: 0; } +@media (max-width: 760px) { + .h4-spacer { display: none; } + h4 { display: inherit; } + h4 + p>.marginnote, h4 + p>.sidenote { + display: none; + } +} /* Override original Tufte CSS */ @@ -47,15 +93,32 @@ p { -ms-hyphens: auto; } -h2, h3 { +h3 { line-height: inherit; } + +h2, h3, h4 { font-style: unset; + margin-top: 2.5rem; } +a:link, .tufte-underline, .hover-tufte-underline:hover { + /*background: unset;*/ + text-shadow: unset; +} + +/* + You can choose between two modes. + The former will display all margin notes in-text. + The latter will add a toggle button. +*/ @media (max-width: 760px) { .sidenote, .marginnote { - /* for now, until toggle works */ display: block; width: 90%; - margin: 2rem 5%; + margin: 1rem 5%; } -} \ No newline at end of file +} +/* +label.mtoggle::before { content: unset; } +@media (max-width: 760px) { + label.mtoggle::before { content: ' ⊕'; } +}*/ diff --git a/bin/en-example.html b/bin/en-example.html index ebaadd9..c03ba76 100644 --- a/bin/en-example.html +++ b/bin/en-example.html @@ -3,7 +3,7 @@ md2tufte - + @@ -22,12 +22,12 @@

md2tufte

-

Exemplary overview document

-

relikd (v20210704)

+

Exemplary overview document  ·  v2021-09-10

+

relikd

This document is an exemplary usage of this tool. Of course it will look better with actual documents when the content is longer and the lines break more nicely.

Features

-

This document was created with md2tufte – a tool which takes a markdown file as input and returns html and pdf as output. It supports the usual markdown syntax and is augmented with a substitution header. To place something in the margin, use the @ == syntax.

-

For further examples, refer to the README file. You can use in-document references.e.g., see section Requirements.

+

This document A HTML version of this document using a responsive layout for small screens is available at https://relikd.github.io/md2tufte/bin/en-example.html was created with md2tufte – a tool which takes a markdown file as input and returns html and pdf as output. It supports the usual markdown syntax and is augmented with a substitution header. To place something in the margin, use the @ == syntax. multi line, super long name desc with various other words than these mere few you saw in the beginning!

+

For further examples, refer to the README file. You can use in-document references. e.g., see section Requirements.

As you see, you can put about anything in the margin. If you want to control that something should be only visible in the pdf version of the document but not in the html version, use the @ =latex= syntax. Currently there is no inverse, i.e., @ =html= will not work.

Requirements

You can use margin images!

@@ -69,3 +69,4 @@ build the intermediate file only. + diff --git a/bin/fonts/OFL.txt b/bin/fonts/LICENSE-Cochineal.txt similarity index 100% rename from bin/fonts/OFL.txt rename to bin/fonts/LICENSE-Cochineal.txt diff --git a/bin/fonts/LICENSE-Piazzolla.txt b/bin/fonts/LICENSE-Piazzolla.txt new file mode 100755 index 0000000..6d6d3db --- /dev/null +++ b/bin/fonts/LICENSE-Piazzolla.txt @@ -0,0 +1,93 @@ +Copyright 2018 The Piazzolla Project Authors (https://github.com/huertatipografica/piazzolla) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/bin/fonts/Piazzolla-Italic.ttf b/bin/fonts/Piazzolla-Italic.ttf new file mode 100644 index 0000000..3ad871d Binary files /dev/null and b/bin/fonts/Piazzolla-Italic.ttf differ diff --git a/bin/fonts/Piazzolla.ttf b/bin/fonts/Piazzolla.ttf new file mode 100644 index 0000000..757168c Binary files /dev/null and b/bin/fonts/Piazzolla.ttf differ diff --git a/bin/fonts/cochineal-doc.pdf b/bin/fonts/cochineal-doc.pdf deleted file mode 100644 index 8a9c748..0000000 Binary files a/bin/fonts/cochineal-doc.pdf and /dev/null differ diff --git a/en-example.html b/en-example.html index ebaadd9..c03ba76 100644 --- a/en-example.html +++ b/en-example.html @@ -3,7 +3,7 @@ md2tufte - + @@ -22,12 +22,12 @@

md2tufte

-

Exemplary overview document

-

relikd (v20210704)

+

Exemplary overview document  ·  v2021-09-10

+

relikd

This document is an exemplary usage of this tool. Of course it will look better with actual documents when the content is longer and the lines break more nicely.

Features

-

This document was created with md2tufte – a tool which takes a markdown file as input and returns html and pdf as output. It supports the usual markdown syntax and is augmented with a substitution header. To place something in the margin, use the @ == syntax.

-

For further examples, refer to the README file. You can use in-document references.e.g., see section Requirements.

+

This document A HTML version of this document using a responsive layout for small screens is available at https://relikd.github.io/md2tufte/bin/en-example.html was created with md2tufte – a tool which takes a markdown file as input and returns html and pdf as output. It supports the usual markdown syntax and is augmented with a substitution header. To place something in the margin, use the @ == syntax. multi line, super long name desc with various other words than these mere few you saw in the beginning!

+

For further examples, refer to the README file. You can use in-document references. e.g., see section Requirements.

As you see, you can put about anything in the margin. If you want to control that something should be only visible in the pdf version of the document but not in the html version, use the @ =latex= syntax. Currently there is no inverse, i.e., @ =html= will not work.

Requirements

You can use margin images!

@@ -69,3 +69,4 @@ build the intermediate file only. + diff --git a/en-example.markdown b/en-example.markdown index f74a6e7..ece570d 100644 --- a/en-example.markdown +++ b/en-example.markdown @@ -1,8 +1,7 @@ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: TITLE : md2tufte -SUBTITLE : Exemplary overview document +SUBTITLE : Exemplary overview document \~·\~ v2021-09-10 AUTHOR : relikd - VERSION : v20210704 TOC : @@@ Features Requirements @@ -22,7 +21,9 @@ A HTML version of this document using a responsive layout for small screens is a ==@ was created with [`md2tufte`](https://github.com/relikd/md2tufte) – a tool which takes a markdown file as input and returns html and pdf as output. It supports the usual markdown syntax and is augmented with a substitution header. -To place something in the margin, use the `@ ==` syntax. +To place something in the margin, use the `@ ==` syntax.@== +[multi line, super long name desc with various other words than these mere few you saw in the beginning!](multi-line-url) +==@ For further examples, refer to the README file. You can use in-document references.@== diff --git a/en-example.pdf b/en-example.pdf index 9059654..aa72580 100644 Binary files a/en-example.pdf and b/en-example.pdf differ diff --git a/src/common-preamble.tex b/src/common-preamble.tex new file mode 100755 index 0000000..8a20b5f --- /dev/null +++ b/src/common-preamble.tex @@ -0,0 +1,75 @@ +\usepackage{fontspec} +\usepackage{babel} +\usepackage{fancyhdr} +\usepackage{hyperref} +\usepackage{xcolor} +\hypersetup{ + colorlinks, + linkcolor={red!50!black}, + citecolor={blue!50!black}, + urlcolor={blue!80!black} +} +\pagestyle{fancy} +\setlength{\parskip}{\medskipamount} +\setlength{\parindent}{0pt} +\usepackage{url} +\usepackage{graphicx} +\usepackage{microtype} + +\setmainfont[ + Path = fonts/, + %Scale = 0.95, + BoldFont = {Cochineal-Bold}, + ItalicFont = {Cochineal-Italic}, + BoldItalicFont = {Cochineal-BoldItalic} +]{Cochineal-Roman} +\setsansfont[ + Path = fonts/, + BoldFont = {Roboto-Bold}, + ItalicFont = {Roboto-Italic}, + BoldItalicFont = {Roboto-BoldItalic} +]{Roboto-Regular} +\setmonofont[ + Path = fonts/, + BoldFont = {iosevka-ss04-bold}, + ItalicFont = {iosevka-ss04-italic}, + BoldItalicFont = {iosevka-ss04-bolditalic} +]{iosevka-ss04-regular} + +\makeatletter + +\usepackage{etoolbox} +\usepackage{caption} + +\setcounter{secnumdepth}{2} + +\usepackage{titlesec} +\titleformat{\section} + {\sffamily\Large}{\thesection.}{0.2em}{} +\titleformat{\subsection} + {\sffamily\normalsize}{\thesubsection.}{0.2em}{} + +\titlespacing{\section}{0pt}{*6}{*1} +\titlespacing{\subsection}{0pt}{*3}{*0.5} + +\usepackage[absolute]{textpos} + +\urlstyle{same} + +\setcounter{secnumdepth}{0} +\def\tightlist{} +\renewcommand\allcapsspacing[1]{{\addfontfeature{LetterSpace=15}#1}} +\renewcommand\smallcapsspacing[1]{{\addfontfeature{LetterSpace=10}#1}} + +\newcommand{\marginsection}[1]{ + \if@noskipsec\leavevmode\fi \par + \paragraph{} + \def\@svsechd{\marginnote{#1}}\@xsect{0pt}} + +\setlength{\parindent}{0pt} + +\AtBeginDocument{ + \def\labelitemi{\normalsize\normalfont\bfseries{--}} +} + +\makeatother diff --git a/src/rules-html-post.sed b/src/rules-html-post.sed old mode 100644 new mode 100755 index 918450f..c9d7a85 --- a/src/rules-html-post.sed +++ b/src/rules-html-post.sed @@ -1,8 +1,3 @@ -# Margin note -#s?==@??g -#s?@==??g -s?@==[[:space:]]*\(.*\)[[:space:]]*==@?\1?g -s?@=latex=\(.*\)==@??g -# sectioning +# Sectioning s?

\ ?g s?\\~?\ ?g + +# Margin note +s?####[[:space:]]*\(.*\)$?

\ +#### \1\ +@== \1 ==@?g + +# Use this to show margin notes inline +s?@=latex=??g +s?@==[[:space:]]*??g +s?[[:space:]]*==@??g + +# OR: use this to enable margin-toggle +# s?@=latex=??g +# s?@==[[:space:]]*?