Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 0.84 KB | None | 0 0
  1. % http://tex.stackexchange.com/q/342509/5764
  2. \documentclass{report}
  3.  
  4. \usepackage{luacode,hyperref}
  5. \usepackage{lipsum}
  6.  
  7. \begin{luacode}
  8.  function inserthref ( s )
  9.    if string.find ( s , '\\chapter' ) == nil then
  10.      s = string.gsub ( s , 'My unique chapter name',
  11.        '\\hyperref[ch:my-unique-chapter-name]{My unique chapter name}' )
  12.      s = string.gsub ( s , 'Introduction',
  13.        '\\hyperref[ch:introduction]{Introduction}' )
  14.    end
  15.    return ( s )
  16.  end
  17. \end{luacode}
  18. \AtBeginDocument{\directlua{luatexbase.add_to_callback (
  19.   "process_input_buffer", inserthref, "inserthref" ) }}
  20.  
  21. \begin{document}
  22.  
  23. \chapter{Introduction}
  24. \label{ch:introduction}
  25.  
  26. \chapter{My unique chapter name}
  27. \label{ch:my-unique-chapter-name}
  28. \lipsum[1-10]
  29.  
  30. See My unique chapter name as well as introduction, Introduction.
  31.  
  32. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement