lib/polytexnic/literal.rb in polytexnic-1.10.3 vs lib/polytexnic/literal.rb in polytexnic-1.10.4

- old
+ new

@@ -219,15 +219,23 @@ figure = language_labels["figure"] fig = language_labels["fig"] listing = language_labels["listing"] equation = language_labels["equation"] eq = language_labels["eq"] - linked_item = "(#{part}|#{chapter}|#{section}|#{appendix}|#{table}|#{box}|#{figure}" + - "|#{fig}\.|#{listing}|#{equation}|#{eq}\.)" + @supported_theorem_types.each do |theorem| + eval("#{theorem} = language_labels['#{theorem}']") + end + theorem_string = @supported_theorem_types.map(&:capitalize).join("|") + linked_item = "(#{part}|#{chapter}|#{section}|#{appendix}|#{table}" + + "|#{box}|#{figure}|#{fig}\.|#{listing}|#{equation}" + + "|#{eq}\.|#{theorem_string})" ref = /(?:#{linked_item}(~| ))*(\\(?:eq)*ref){(.*?)}/i string.gsub!(ref) do - "\\hyperref[#{$4}]{#{$1}#{$2}#{$3}{#{$4}}}" + # The outermost braces handle the edge case of a ref inside + # square-backet args, as in `\proof[Theorem~\ref{th:foo}]`. + # See https://tex.stackexchange.com/questions/513460/how-to-add-a-hyperref-inside-theorem-title-or-proof-name + "{\\hyperref[#{$4}]{#{$1}#{$2}#{$3}{#{$4}}}}" end end # Handles non-ASCII Unicode characters. # The Tralics part of the pipeline doesn't properly handle Unicode, @@ -305,6 +313,5 @@ Polytexnic::Literal.math_environments.map do |s| Regexp.escape(s) end.join('|') end end -