- // \hypersetup \AtBeginDocument, since the class might
- // load hyperref late, see bug #7048.
- if (hyperref_already_provided && !opt.empty())
- os << "\\AtBeginDocument{%\n";
- os << from_utf8(opt);
- if (hyperref_already_provided && !opt.empty())
- os << "}";
+ // \hypersetup \AtBeginDocument if hypersetup is not (yet)
+ // defined. In this case, the class loads hyperref late
+ // (see bug #7048).
+ if (hyperref_already_provided && !opt.empty()) {
+ os << "\\ifx\\hypersetup\\undefined\n"
+ << " \\AtBeginDocument{%\n "
+ << from_utf8(opt)
+ << " }\n"
+ << "\\else\n "
+ << from_utf8(opt)
+ << "\\fi\n";
+ } else
+ os << from_utf8(opt);