2nd Update
Package ocgx2
, and Ghostscript releases >=9.15 allow for creating PDF layers (OCGs) with latex
+dvips
+ps2pdf
.
\documentclass{article}
\usepackage{ocgx2}
\begin{document}
\switchocg{a b}{\fbox{Swap visibility}}\\[1ex]
\begin{ocg}{A}{a}{1}
Some text, initially visible.
\end{ocg}
\begin{ocg}{B}{b}{0}
Some text, initially \emph{in}visible.
\end{ocg}
\begin{ocg}{A}{a}{0} %initial visibility of re-opened OCG cannot be changed
Some more text, initially visible.
\end{ocg}
\end{document}
1st Update (obsolete)
The package combination ocgx
+fixocgx
, together with the recent Ghostscript release 9.15 allows for creating PDF layers (OCGs) with latex
+dvips
+ps2pdf
.
\documentclass{article}
\usepackage{ocgx}
\usepackage{fixocgx}[2015/01/26]
\begin{document}
\switchocg{a b}{\fbox{Swap visibility}}\\[1ex]
\begin{ocg}{A}{a}{1}
Some text, initially visible.
\end{ocg}
\begin{ocg}{B}{b}{0}
Some text, initially \emph{in}visible.
\end{ocg}
\begin{ocg}{A}{a}{0} %initial visibility of re-opened OCG cannot be changed
Some more text, initially visible.
\end{ocg}
\end{document}
In order to create layers in PDFs using OCGs (optional content groups), the content in the page stream that is to be made optional must be enclosed in a /OC ... BDC
-EMC
bracket.
Unfortunately, the /BDC
and /EMC
pdfmarks, which serve this purpose, are not supported by Ghostscript's ps2pdf
(according to gdevpdfm.c
in the Ghostscript sources).
Currently, only Adobe Distiller supports them.
As of Ghostscript-9.15, /BDC
and /EMC
pdfmarks and thus OCGs are fully supported.
The corrected code example from the original posting using the low-level pdfmark
implementation, to be run through latex
->dvips
-> ps2pdf
or Distiller, reads:
\documentclass{article}
\newcommand{\setupOCG}{
\special{ps: mark /_objdef {ocg1} /type/dict /OBJ pdfmark}
\special{ps: mark {ocg1} <</Type/OCG /Name (My first layer)>> /PUT pdfmark}
\special{ps: mark /_objdef {ocg2} /type/dict /OBJ pdfmark}
\special{ps: mark {ocg2} <</Type/OCG /Name (My second layer)>> /PUT pdfmark}
%register it and configure its default behaviour
\special{ps:mark {Catalog} <<
/OCProperties <<
/OCGs [{ocg1} {ocg2}]
/D <</BaseState/ON /Order [{ocg1} {ocg2}] /OFF [{ocg1}] >> %first layer invisible
>>
>> /PUT pdfmark}
}
\newcommand{\myocg}[2]{%
\special{ps: mark /OC {#1} /BDC pdfmark}#2\special{ps: mark /EMC pdfmark}%
}
\setupOCG
\begin{document}
\myocg{ocg1}{I am NOT visible on the first layer.}
\myocg{ocg2}{I am visible on the second layer.}
\end{document}
The code in my answer to TeX accents do not seem to work with fontspec and xe/lua/latex gives the idea, but for the dot above some additional code is needed.
\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont{Minion Pro} % a font without Latin Ext. Additional
\usepackage{newunicodechar}
\UndeclareUTFcomposite[\UTFencname]{x0101}{\=}{a}
\UndeclareUTFcomposite[\UTFencname]{x1E43}{\d}{m}
\UndeclareUTFcomposite[\UTFencname]{x1E45}{\.}{n}
\makeatletter
\let\d\relax
\DeclareRobustCommand{\d}[1]
{\hmode@bgroup
\o@lign{\relax#1\crcr\hidewidth\ltx@sh@ft{-1ex}.\hidewidth}\egroup
}
\let\.\relax
\DeclareRobustCommand{\.}[1]
{\hmode@bgroup\vbox{% \o@lign has \vtop
\lineskiplimit\z@
\baselineskip\z@skip
\lineskip.25ex
\ialign {##\crcr\hidewidth.\hidewidth\crcr#1\crcr}}\egroup
}
\makeatother
\newunicodechar{ā}{\={a}}
\newunicodechar{ṃ}{\d{m}}
\newunicodechar{ṅ}{{\.n}}
\begin{document}
German Umlaute:
\begin{itemize}
\item Unicode characters: ä ö ü Ä Ö Ü
\item by \LaTeX command: \"a \"o \"u \"A \"O \"U
\end{itemize}
a with macron above:
\begin{itemize}
\item by function: ā
\item by \LaTeX: {\=a}
\end{itemize}
m with dot underneath:
\begin{itemize}
\item by function: ṃ
\item by \LaTeX: \d{m}
\end{itemize}
n with dot above:
\begin{itemize}
\item by function: ṅ
\item by \LaTeX: \.n
\end{itemize}
\end{document}
Best Answer
In principle, it is possible. However, someone has to add the support for xetex into the packages. You may try to compile the following text with xetex. The second line is in optional OCG and can be switched off. Stolen from here.