latex使用\hl进行高亮时遇到引用总是报错,显示少了括号或者多了括号

Problems with \ref when using soul for highlighting
报错
I’ve run across a `}’ that doesn’t seem to match anything.

解决方法解决方法

Enclosing the \ref{x} in { } works. soul then takes it as one element instead of breaking it up, I guess. It seems to me that it reads both \ref and {x} in two steps and sets it together again while adding another set of braces, i.e. the result is \ref{{x}}. This doesn’t matter much for font commands but \ref takes the inner braces as part of the label name. This causes the warning about the unknown label. The error is caused because \ref is then also expanded by soul inside a { } group, i.e. {\ref}. Don’t ask me why.

Note that you can’t label a \section* because it doesn’t has a number.

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames]{color}
\usepackage{soul}
%\soulregister{\ref}{1}
\begin{document}

\section{x}\label{x}

\section{y}
\hl{ Some text.
   Section~{\ref{x}}.
}
\end{document}

我尝试的是在 \ref{x}外面增加个大括号就行变成{\ref(x)}

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值