In asciidoc how do I execute a macro only for pdf generation?

1.1k views Asked by At

In the asciidoc there is an image that I'd like to include only for PDF output. Is there a kind of attribute I can pass to image:: so that the image is processed for PDF generation, and ignored when generating epubs etc.? Or more probably by using ifdef, but how exactly?

2

There are 2 answers

0
Jmini On BEST ANSWER

You can use the ifdef directive like this:

Some text for all outputs.

ifdef::backend-pdf[]
This is only displayed in the PDF document, you can use image:
image::mypict.png[]
endif::[]
2
U. W. On

If you need a simple and small solution, I would prefer Jminis answer.

For cases that need more differentiation, you can define your own filter parameters, for different types of output, that can be defined as parameters in the commandline call. You can filter your content as follows e.g. if you want to differ between different audiences as well.

Some text for all outputs.

ifeval::["{myfilter1}"=="pdf"]
  This content is pdf-only!

  ifeval::["{myfilter2}"=="adminpdf"]
    This content is admin-pdf-only!
  endif::[]
endif::[]

You can add the parameters in the commandline call as follows:

--attribute myfilter1='pdf'

The exact expression of the command depends on your system. The following syntax could work (I cannot test it at the moment in the absence of a asciidoc-setup).

OS X asciidoc -> docbook:

SCRIPT=${...path to asciidoc installation...}/asciidoc.py
INPUT=myAsciidocInput.ad
OUTPUT=MyDocBookOutput.xml
MYFILTER="--attribute myfilter1='pdf' --attribute myfilter2='adminpdf'"
python "$SCRIPT" -o "$OUTPUT" "$MYFILTER "$INPUT"

WIN asciidoc -> docbook:

set SCRIPT=%{...path to asciidoc installation...}%\asciidoc.py
set INPUT=myAsciidocInput.ad
set OUTPUT=MyDocBookOutput.xml
set MYFILTER=--attribute myfilter1='pdf' --attribute myfilter2='adminpdf'
python "%SCRIPT%" -o "%OUTPUT%"