Forgot password?
 Create new account
View 513|Reply 10

nameref引用时,如果断开词怎么引用

[Copy link]

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

abababa Posted at 2022-3-24 15:26:22 |Read mode
如题,我在定理里写的是:\begin{theorem}[Minkowski 不等式]\label{thm:01:01:01}

我引用时用的是\nameref{thm:01:01:01},但它只引用到“不等式”这三个字,前面那个人名没引用到。以前都是写汉字的,像柯西不等式之类的,没发现这个问题,这个人名太长了,我想写英文,结果引用就发现这个问题了。这要怎么弄呢?

Related threads

700

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2022-3-24 15:40:58
\nameref 是什么宏包的功能?

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2022-3-24 16:03:49
回复 2# kuing

我用的引用包有两个:
\usepackage[pdfencoding=auto,psdextra,colorlinks,linkcolor=red,anchorcolor=blue,citecolor=blue]{hyperref}
\usepackage{cleveref}
我觉得是第一个吧,因为文档里说"Note: hyperref loads package nameref at \begin{document}",所以它应该是自动被加载的吧。

700

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2022-3-24 16:13:20
原来如此,我用 hyperref 这么久竟然不知道这个命令

700

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2022-3-24 16:19:13
我这里无法重现该问题,以下代码:
  1. \documentclass[UTF8]{ctexart}
  2. \usepackage{amsthm}
  3. \usepackage[pdfencoding=auto,psdextra,colorlinks,linkcolor=red,anchorcolor=blue,citecolor=blue]{hyperref}
  4. \usepackage{cleveref}
  5. \newtheorem{theorem}{定理}
  6. \begin{document}
  7. \begin{theorem}[Minkowski 不等式]\label{thm:01:01:01}
  8. \end{theorem}
  9. \nameref{thm:01:01:01}
  10. \end{document}
Copy the Code
xelatex两次,引用结果正常。

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2022-3-24 16:40:09
回复 5# kuing

我也不知道哪出了问题,精简以后也不能重现主楼的情况,但是也不是正常的:
  1. \documentclass[a4paper]{book}
  2. % 使用到的包
  3. \usepackage{amsmath}
  4. % 定理环境
  5. \usepackage[amsmath, thmmarks]{ntheorem}
  6. \newtheorem{theorem}{定理}[section]%缩写thm
  7. \newcommand\theoremautorefname{定理}
  8. \usepackage[pdfencoding=auto,psdextra,colorlinks,linkcolor=red,anchorcolor=blue,citecolor=blue]{hyperref}
  9. \usepackage{cleveref}
  10. % 字体
  11. \usepackage[slantfont,boldfont]{xeCJK}
  12. \setCJKmainfont{WenQuanYi Micro Hei}
  13. \begin{document}
  14. \chapter{第一章}
  15. \section{第一节}
  16. \begin{theorem}[Minkowski 不等式]\label{thm:01:01:01}
  17. Minkowski 不等式
  18. \end{theorem}
  19. 根据\autoref{thm:01:01:01}有:
  20. 根据\nameref{thm:01:01:01}有:
  21. \end{document}
Copy the Code

700

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2022-3-24 17:14:51
回复 6# abababa

可能和 ntheorem 包不兼容,我将上述代码第5行改为 \usepackage{amsthm} 就正常了。

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2022-3-24 21:13:50
回复 7# kuing

搜到两篇帖子:
tex.stackexchange.com/questions/579870/namere … ead-of-theorem-title

guyrutenberg.com/2012/12/15/nameref-doesnt-wo … theorem-environment/

都是这个问题。不过不想用帖子里的解决方法,觉得不自然。

700

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2022-3-25 01:22:38
回复 8# abababa

链接1是说 ntheorem 无设置 \@currentlabelname,所以 \nameref 就失败鸟。
根据链接1的方法,想出如下方法,未必很好,估计也不算“自然”,姑且一试:
  1. \documentclass[a4paper]{book}
  2. % 使用到的包
  3. \usepackage{amsmath}
  4. % 定理环境
  5. \usepackage[amsmath, thmmarks]{ntheorem}
  6. \makeatletter
  7. \def\@setname#1[#2]{\begin{#1}[#2]\def\@currentlabelname{#2}}
  8. \newcommand\setname[1]{\@ifnextchar[{\@setname{#1}}{\begin{#1}}}
  9. \makeatother
  10. \newtheorem{tmpthm}{定理}[section]
  11. \newcommand\tmpthmautorefname{定理}
  12. \newenvironment{theorem}{\setname{tmpthm}}{\end{tmpthm}}
  13. %引理类似:
  14. \newtheorem{tmplem}{引理}[section]
  15. \newcommand\tmplemautorefname{引理}
  16. \newenvironment{lemma}{\setname{tmplem}}{\end{tmplem}}
  17. \usepackage[pdfencoding=auto,psdextra,colorlinks,linkcolor=red,anchorcolor=blue,citecolor=blue]{hyperref}
  18. \usepackage{cleveref}
  19. % 字体
  20. \usepackage[slantfont,boldfont]{xeCJK}
  21. %\setCJKmainfont{WenQuanYi Micro Hei}
  22. \begin{document}
  23. \chapter{第一章}
  24. \section{第一节}
  25. \begin{theorem}[Minkowski 不等式]\label{thm:01:01:01}
  26. Minkowski 不等式
  27. \end{theorem}
  28. 根据\autoref{thm:01:01:01}有:
  29. 根据\nameref{thm:01:01:01}有:
  30. \begin{lemma}[XXX不等式]\label{lem:01:01:01}
  31. blabla
  32. \end{lemma}
  33. 根据\autoref{lem:01:01:01}有:
  34. 根据\nameref{lem:01:01:01}有:
  35. \end{document}
Copy the Code
PS、我注释掉了 \setCJKmainfont{WenQuanYi Micro Hei} 是因为我这里没这字体。

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2022-3-25 12:08:46
回复 9# kuing
这个也挺好,至少是统一地写在导言那里,不用每个定理都改一次。我现在就等着能不能升级之后变正常了。

700

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2022-3-25 12:12:52
回复 10# abababa

得等 ntheorem 的作者打补丁了

手机版Mobile version|Leisure Math Forum

2025-4-21 01:21 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list