- opt += "backref=" + convert<string>(backref) + ',';
- opt += "pagebackref=" + convert<string>(pagebackref) + ',';
- opt += "\n ";
- opt += "colorlinks=" + convert<string>(colorlinks) + ',';
- if (!pagemode.empty())
- opt += "pdfpagemode=" + pagemode + ',';
- if (!quoted_options.empty()){
- opt += "\n ";
- opt += quoted_options_get();
+ // use in \\usepackage parameter as not all options can be handled inside \\hypersetup
+ if (!hyperref_already_provided) {
+ opt = rtrim(opt, ",");
+ opt = "\\usepackage[" + opt + "]\n {hyperref}\n";
+
+ if (!hyperset.empty())
+ opt += "\\hypersetup{" + hyperset + "}\n";
+ } else {
+ // only in case hyperref is already loaded by the current text class
+ // try to put it into hyperset
+ //
+ // FIXME: rename in this case the PDF settings dialog checkbox
+ // label from "Use Hyperref" to "Customize Hyperref Settings"
+ // as discussd in bug #6293
+ opt = "\\hypersetup{" + rtrim(opt + hyperset, ",") + "}\n";
+ }
+
+ // hyperref expects LICR macros for non-ASCII chars.
+ // Usually, "(lua)inputenc" converts the input to LICR, with XeTeX utf-8 works, too.
+ // As hyperref provides good coverage for \inputencoding{utf8}, we can try
+ // this if the current input encoding does not support a character.
+ // FIXME: don't use \inputencoding if "inputenc" is not loaded (#9839).
+ if (need_unicode && enc && enc->iconvName() != "UTF-8") {
+ if (runparams.flavor != OutputParams::XETEX)
+ os << "\\inputencoding{utf8}\n";
+ os << setEncoding("UTF-8");
+ }
+ // If hyperref is loaded by the document class, we output
+ // \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);
+ if (need_unicode && enc && enc->iconvName() != "UTF-8") {
+ os << setEncoding(enc->iconvName());
+ if (runparams.flavor != OutputParams::XETEX)
+ os << "\\inputencoding{" << from_ascii(enc->latexName()) << "}\n";