- for (int k = 0; k < 6; k++) {
- for (int i = 0, pos;
- (pos = name.find(chars_name[k], i)) != string::npos;
- i = pos + 2) {
- name.replace(pos,1,backslash + chars_name[k] + braces);
- }
+
+ // The characters in chars_url[] need to be escaped in the url
+ // field because otherwise LaTeX will fail when the hyperlink is
+ // within an argument of another command, e.g. in a \footnote. It
+ // is important that they are escaped as "\#" and not as "\#{}".
+ // FIXME this is not necessary in outside of commands.
+ for (int k = 0; k < 2; k++)
+ for (size_t i = 0, pos;
+ (pos = url.find(chars_url[k], i)) != string::npos;
+ i = pos + 2)
+ url.replace(pos, 1, from_ascii("\\") + chars_url[k]);
+
+ // add "http://" when the type is web (type = empty)
+ // and no "://" is given
+ if (url.find(from_ascii("://")) == string::npos
+ && utype.empty())
+ url = from_ascii("http://") + url;
+
+ } // end if (!url.empty())
+
+ if (!name.empty()) {
+ name = params().prepareCommand(runparams, name,
+ ParamInfo::HANDLING_LATEXIFY);
+ // replace the tilde by the \sim character as suggested in the
+ // LaTeX FAQ for URLs
+ if (getParam("literal") != "true") {
+ docstring const sim = from_ascii("$\\sim$");
+ for (size_t i = 0, pos;
+ (pos = name.find('~', i)) != string::npos;
+ i = pos + 1)
+ name.replace(pos, 1, sim);