asciidoc-pdf: How to use custom styles - asciidoctor

How can I use custom styles (font-size, font-color etc) in asciidoctor-pdf.
I've read the theming guide and tried to add settings ins xxx-theme.yml without any success.
Also the the marked styling (with #) doesn't work in my pdf example.

You should have to create your own YAML theme and then use the pdf-style option like this
$ asciidoctor-pdf src/main.adoc -a pdf-style=themes/my-theme.yml
Documentation here

If you want to see how a xxx-theme.yml can be used inside a maven build, you can refer to the asciidoctor-pdf-with-theme-example project. It generates two pdf files (one styled with the yml file and using the default PDF style)

Using a custom style is mandatory if you want a result similar to what you get when exporting to html or epub3, because the default theme do not map default (css/html) styles from asciidoc.
Create a file with the "-theme.yml" suffix, like "my-theme.yml"
then insert:
extends: default
role:
red:
font-color: #c5000c
maroon:
font-color: #4f2400
green:
font-color: #366251
navy:
font-color: #4974a5
do reference in this yaml all color names along with its respective encoding (the one in this example are not exact), and used like that [.green]#SomeTextThatSouldLookGreen# in your *.adoc file.
(I am using role in this sample theme for simplicity but other ways may fit your needs, see the theming-guide that starts by an explaination about customizing fonts)
then call it either using command-line options:
asciidoctor-pdf src/main.adoc -a pdf-style=themes/my-theme.yml
asciidoctor-pdf src/main.adoc -a pdf-stylesdir=./themes -a pdf-style=my
or by inserting the followinfgspecific tag in your source *.adoc file:
:pdf-theme: themes/pdf-theme.yml

Related

Can I change the font used in source blocks by Asciidoctor PDF?

Is it possible to specify a different font for use in the source blocks of a PDF generated by asciidoctor-pdf?
I'm guessing it has something to do with the theme I'm using (currently just the default), but I've checked the theming guide and can't see any configuration related to the source blocks specifically.
Yes it is possible and yes it has to do with the theming. You can check the default asciidoctor-pdf theming under https://github.com/asciidoctor/asciidoctor-pdf/blob/main/data/themes/default-theme.yml, you will see line 188 # code is used for source blocks (perhaps change to source or listing?), this is what you need to change.
The simplest way is to create your own theme custom-theme.yml by extending the default theme and set the font family you want, in my example Courier, this works:
extends: default
font:
catalog:
merge: true
Courier:
normal: cour.ttf
bold: courbd.ttf
italic: couri.ttf
bold_italic: courbi.ttf
code:
font_family: Courier
I organize my files like this:
yourFile.adoc
resources/themes/custom-theme.yml
resources/fonts/cour.ttf
resources/fonts/courbd.ttf
resources/fonts/couri.ttf
resources/fonts/courbi.ttf
You then need to call asciidoctor-pdf with your new theme and a link to the fonts path, something like this:
asciidoctor-pdf -a pdf-theme=resources/themes/custom-theme.yml -a pdf-fontsdir="resources/fonts;GEM_FONTS_DIR" yourFile.adoc

PurgeCSS and Tailwind CSS, how to preserve responsive classes using the Command Line Interface?

I have the "full" 3.9 MB Tailwind CSS file and successfully applied PurgeCSS to reduce it to 9 kB. But it also purged all responsive classes like md:px-6, they don't show up in my purged version.
Note: this question is for using the command line interface (CLI)
This is what I did:
purgecss --css ~/Desktop/Projects/Flask/Project1/build/static/css/main.css --content ~/Desktop/Projects/Flask//Project1/build/**/*.html --output ~/Desktop/Projects/Flask/Project2/static/css/main.css
I chose to create the output file in a different folder (Project2) so that I could check on the input vs output.
One thing I tried is to add --safelist [/md/], but didn't help. In fact the safelist didn't seem to be used at all...
(I use CLI since it is part of a bigger Python Flask project)
PurgeCSS relies on extractors to get the list of selectors used in a file. It provides a default extractor that is working fine with a wide variety of file types, but it can be limited and does not fit every CSS framework out there.
The default extractor considers every word of a file as a selector but it doesn't consider special characters like the colon (:) which is heavily used in Tailwind CSS.
So, by default, PurgeCSS removes responsive (md:px-6), hover (hover:bg-gray-500), etc. classes. To avoid this, Tailwind has its own extractor. You could use this (or your very own) extractor but the PurgeCSS CLI has limited options and it's missing a defaultExtractor option.
Luckily, it accepts a config file option, so if you create your own purgecss.config.js file and add a default extractor in there, it will preserve these classes too. You can also add your other options to this file.
I used to use this simple extractor which will work for you too:
(content) => content.match(/[\w-/:]+(?<!:)/g) || []
Your config file will look like this:
// purgecss.config.js
module.exports = {
content: ['build/**/*.html'],
css: ['build/static/css/main.css'],
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [],
output: 'static/css/main.css',
};
And you can use the following command to run PurgeCSS with the above config:
purgecss --config ./purgecss.config.js
Edit:
As Fred mentioned in their comment, if you also want to include classes like px-2.5, you'll need to add a . to the character set:
(content) => content.match(/[\w-/:.]+(?<!:)/g) || []

SublimeText3 + pandown + pandoc: includes_paths not working

I'm using ST3+pandown+pandoc to convert markdown to PDF. I want to use pandown's includes_paths setting to avoid typing the path to my image directory every time. I haven't been able to get it to work, however. Here's a MWE:
I have a directory structure as follows:
text.markdown
test/img.pdf
In text.markdown, I have:
![](img.pdf)
I've got set includes_paths as follows in Pandown.sublime-settings:
"includes_paths":
[
"test/"
],
But, no dice. I've also tried with an absolute path, ./test, and test. Any ideas?
I think Pandown's includes_paths only applies to Pandoc's --include-in-header, --include-before-body and --include-after-body options, not image locations etc.
From Pandown.sublime-settings about includes_paths:
Pandoc apparently doesn't search for values for its --include
arguments anywhere but the working directory, which makes
working from a standard stylesheet or standard script
sort of tedious.
A workaround, using the graphicx package loaded in the YAML header and \graphicspath:
---
header-includes:
- \usepackage{graphicx}
---
\graphicspath{{test/}}
![](img.pdf)
Pandoc will say that it can't find img.pdf, but the image will be present in the final pdf.

Gifs on Sailfish-os

I came here with a little problem, i can't use any local .gif in my code.
I work on Linux with QtCreator and the Sailfish VM to make a Sailfish-os application.
I tried first this example, without any success.
Rectangle {
width: animation.width
height: animation.height
AnimatedImage { id: animation; source: "../images/animatedimageitem.gif"}
}
The execution return :
QML AnimatedImage: Error Reading Animated Image File file:///bla/bla/.....
Same problem with other permissions on the gif and with an other gif.
After some researches I found this page where someone indicate to download a plugin, but Qt declare (I wish i could put a link but i'm new -_-', see comments) that gifs are already support by default.
The plugin was finally unobtainable and I found this Sailfish/bin/plugins/imageformats/libqgif.so in my directories.
So what can i do to show a gif on this damn thing ?
The error you are seeing is probably related to filepaths. Gifs are supported, AFAIK.
Instead of coding the path that way, consider the usage of a resource file to improve portability and platform independence.
Create a new resource file (File -> New File or project -> Qt -> Qt Resource File)
The property editor opens, click Add in the bottom then Add prefix and set a prefix such as / (or whatever you like!)
Click again to select Add files and insert your image
Right-click the newly added image entry and copy resource path to Clipboard
Build -> Run qmake (fundamental to ensure correct compilation)
The path you copied in the clipboard should be of the form:
://PATH_TO_IMAGE.gif
Now, given your QML code, I can guess the image folder is inside source code at the same level as the QML folder. Hence, if you added the .gif file from that folder you would have the following path in the clipboard:
://images/name.gif
This can be prepended with the prefix to obtain the final path. If your prefix is set to /, as we did above, the final string to be set in the source property of your AnimatedImage would be:
"qrc:///images/name.gif"
Obviously, a different prefix or a different path would result in a different final path.
Well..... I just put it on my phone (Jolla) and the gif works well. So this is the VM who doesn't seems to like gifs ...
Thanks for help though,
Psycho.

Using a Twig Extension

I am trying to use teh Twig i18n Extension.
As far as I can tell the file I need is here:
https://github.com/fabpot/Twig-extensions/blob/master/lib/Twig/Extensions/Extension/I18n.php
Now I am not quite sure where to save this file
I have Twig in a folder called includes/lib (/includes/lib/Twig). I see a folder Extension under Twig. Do I save it here?
After I save it, do I need to do a "require_once" to the file or will Twig_Autoloader do the job for me?
I am not using Symfony2
Thanks
Craig
Here is the complete answer that worked for me:
Copy the file in Twig-Verzeichnis (extract i18n.zip in Twig).
For the I18n extension it would be Twig/Extensions/Extension/I18n.php
Eventually add other files requred by I18n. You will see what these are by the error messages that come. I had to add "Twig/Extensions/Node/Trans.php" and "Twig/Extensions/TokenParser/Trans.php".
In your config file add the following:
// Set language to German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("project_de_DE", "./locale");
// Choose domain
textdomain("projectl_de_DE");
Register the Twig Extension
$twig->addExtension(new Twig_Extensions_Extension_I18n());
Create the directory locale/de_DE/LC_MESSAGES
Create the PO file (the easisest is to have a sample file to start from)
Open the file in a normal text editor (be sure to use utf-8 encoding) and start translating
Open the PO-Datei with PoEdit (www.poedit.net/)
Save to locale/de_DE/LC_MESSAGES (a MO-Datei will be created).
Add the translation to the appropriate places in the Twig-Template with
{% trans 'Text in the original language' %}`
You need to register this extension with Twig:
$twig->addExtension(new Twig_Extensions_Extension_I18n());
If your installation is configured correctly, the autoloader should do the job of including the file. If not, you could include the file manually or make the installation with composer.
It seems the "proper" way to install these extensions without Composer is as follows:
Download a release from https://github.com/fabpot/Twig-extensions/releases
Copy the contents of the lib/ directory somewhere to your project
include the file .../Twig/Extensions/Autoloader.php
Register autoloader: Twig_Extensions_Autoloader::register();
Continue as explained in the doc: http://twig.sensiolabs.org/doc/extensions/i18n.html

Resources