2

I add \href in \subsection{}, this make the url become all capital, how can I deal with this?

For example, I use \subsection{\href{http://finance.sina.com.cn/roll/2018-06-30/doc-iheqpwqz3115534.shtml}{some text}} and run latex, it shows like this. enter image description here And It contains an url.

Then when I click the link, the url becomes http://finance.sina.com.cn/ROLL/2018-06-30/DOC-IHEQPWQZ3115534.SHTML like this: enter image description here in the web-browser. All the letters become capital, this url cannot open the right website.

What can I do to fix this? I want the url can open the right website. Thank you.

Felix LL
  • 151
  • 3
    Copying the example in your post body, I do not replicate the behaviour you describe. Please could you produce a Minimum Working Example which reproduces the problem? – preferred_anon Jul 06 '18 at 07:36
  • 1
    An example that could reproduce this is `\documentclass[british]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{babel} \usepackage{hyperref}

    \begin{document} \MakeUppercase{\href{http://example.com/lowercase}{some text}}

    \uppercase{\href{http://example.com/lowercase}{some text}} \end{document}`

    – moewe Jul 07 '18 at 12:21
  • 1
    Maybe https://tex.stackexchange.com/q/274734/35864 can help – moewe Jul 07 '18 at 12:22
  • The work-around in the linked question seems to work here is well, `\documentclass[british]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{babel} \usepackage{hyperref}

    \protected\def\mylink{http://example.com/lowercase}

    \begin{document} \MakeUppercase{\href{\mylink}{some text}}

    \uppercase{\href{\mylink}{some text}} \end{document}` but maybe there is something cleverer.

    – moewe Jul 07 '18 at 12:24
  • Sir, but if you use \href in \subsection{} like \subseciont{\href{}{}}, all the letters will become upper case. – Felix LL Jul 07 '18 at 12:45
  • Well the second code with the work-around I posted avoids the URL becoming capitalised. Naturally the "some text" still becomes "SOME TEXT" because that is how your document class formats section headings. What exactly is the output you want? And what does your document look like (show an MWE, please). – moewe Jul 07 '18 at 12:51
  • Since the url becomes the url becomes http://finance.sina.com.cn/ROLL/2018-06-30/DOC-IHEQPWQZ3115534.SHTML, it cannot open the right page. I want it still be http://finance.sina.com.cn/roll/2018-06-30/doc-iheqpwqz3115534.shtml where the letters are still in lower case, and this can open the pages correctly. Thank you. – Felix LL Jul 08 '18 at 03:15
  • I add some MWE in the question, can you please tell me how to fix it. – Felix LL Jul 09 '18 at 07:22
  • Use \lowercase{\href{http://example.com/lowercase}{some text}} – Mu30 murugans2katgmail Jul 09 '18 at 07:34

3 Answers3

2

Something like this will work! :- \subsection{\texorpdfstring{\lowercase{\href{http://finance.sina.com.cn/roll/2018-06-30/doc-iheqpwqz3115534.shtml}{\MakeUppercase{some text}}}}{}}

Since by default, the whole text in a subsection is in upper-case, hence after wrapping \lowercase over whole \href part, this upper-case has to be done forcefully (here using \MakeUppercase).

Also, \texorpdfstring has been used to avoid the warning:
Hyperref warning - Token not allowed in a PDF string

(There may be other work-arounds too)

1

There is an answer to a similar question here: Hyperref capitalizes the URL
which worked for me!

Check this example out:

\documentclass[12pt,a4paper]{article}
\usepackage[left=1.50cm, right=1.50cm, top=1.50cm, bottom=1.50cm]{geometry}
\usepackage{hyperref}
\newcommand{\runsubsection}[1]{\uppercase {#1} \normalfont}

\protected\def\Myurl{\href{https://drive.google.com/file/d/someUPPERandLowercaseURL123456/view}}

\begin{document} Here is an example:\ Hover your mouse over the urls to see what url they are representing:\ there are the same urls inside the same command($\backslash$runsubsection), but the $\backslash$uppercase command converts the first url to UPPERCASE.\[10pt]

\runsubsection{\href{https://drive.google.com/file/d/someUPPERandLowercaseURL123456/view}{some Normal Text for url}}\\

\runsubsection{\Myurl{some Normal Text for url}}

\end{document}

  • 1
    Could you add some code here showing what you're talking about? The question you link to was closed because it looks like OP was putting \href in a \section, but didn't actually do so in their code, so the answer doesn't really reflect what's happening in this question. – Teepeemm Oct 05 '22 at 02:36
0

Tried many ways for hours and got myself caught into a simple solution instead of including a link into subsection. Do the opposite.

Before : \subsection{\href{sometext.com}{some text}}

Wasn't working because some inbuilt function capitalized the link.

After : \href{sometext.com}{\subsection{some text}}

This finally worked for me