TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to display ocgs in a pdf and use the ocgx package to achieve this. Sometimes the content I have in the environment is so long it needs a page break. This is incompatible with the ocg system and the content on the second page is always displayed instead of being optional. A simple fix would be to detect if the ocg is going to contain a page break and split the environment, e.g.


would be detected and the output would resemble the result of e.g.




How can I achieve this? I tried wrapping in a mdframed with beforebreak and afterbreak hooks to break and restart the ocg environment but I don't think ocgs like being nested in other environments...

share|improve this question
I think the ocgs-p package is making things unneccessarily difficult here. From all I see, you should be able to use \ocg to start and \endocg to end an OCG, without nesting problems. – Stephan Lehmke Dec 2 '13 at 16:00

I've been trying this myself but don't have the expertise to dig into mdframed.dtx and extract the obviously necessary box-splitting code. I've hacked together what seems to be a workable solution from Breakable vboxes.

I'd appreciate some help converting this plain-texy solution into a more latexy one.




\def\continuesplitting{\null % In case this starts a new page
    \setbox\partialocgbox=\vsplit\totalocgbox to\dimen255

%TODO give this macro an appropriate name



share|improve this answer

Package ocgx2 (as of v0.11, [2015/11/23]) can do this automatically:






share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.