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.

9
  • 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? Jul 6, 2018 at 7: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 7, 2018 at 12:21
  • 1
    Maybe tex.stackexchange.com/q/274734/35864 can help
    – moewe
    Jul 7, 2018 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 7, 2018 at 12:24
  • Sir, but if you use \href in \subsection{} like \subseciont{\href{}{}}, all the letters will become upper case.
    – Felix LL
    Jul 7, 2018 at 12:45

3 Answers 3

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
  • 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 5, 2022 at 2:36
1

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 😊

2
  • Welcome to TeX.SE!
    – Mensch
    Jan 4 at 18:56
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 4 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .