diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,16 @@
+## 0.3.17.0
+
+-   Bump minimal pandoc version to 3.1.8
+
+
+    Pandoc doesn't use hypertarget since 3.1.7, and inserts `label`s for named spans. This was messing with pandoc-crossref logic, hence required some changes. 3.1.7 has an unfortunate bug which prevents figures from working in LaTeX, hence the minimal version is 3.1.8.
+
+-   Bump dependencies for GHC to 9.6.2, bump GHC to 9.6.2 on CI for Linux and macOS
+
+    Windows is still on 9.0, because newer versions segfault on CI.
+
+-   Minor code clean-up
+
 ## 0.3.16.0
 
 - Add `number` attribute
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks.hs
@@ -51,7 +51,7 @@
   where
     runSplitMath opts
       | tableEqns opts
-      , not $ isLatexFormat (outFormat opts)
+      , not $ isLatexFormat opts
       = everywhere (mkT splitMath)
       | otherwise = id
 
@@ -101,11 +101,11 @@
   opts <- ask
   if "eq:" `T.isPrefixOf` label || T.null label && autoEqnLabels opts
   then do
-    replaceRecurse . (<> xs) =<< if isLatexFormat $ outFormat opts
+    replaceRecurse . (<> xs) =<< if isLatexFormat opts
       then
         pure [RawInline (Format "latex") "\\begin{equation}"
         , Span spanAttr [RawInline (Format "latex") eq]
-        , RawInline (Format "latex") $ mkLaTeXLabel label <> "\\end{equation}"]
+        , RawInline (Format "latex") $ "\\end{equation}"]
       else do
         (eq', idxStr) <- replaceEqn spanAttr eq
         pure [Span (label,clss,setLabel opts idxStr attrs) [Math DisplayMath eq']]
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/CodeBlock.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/CodeBlock.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/CodeBlock.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/CodeBlock.hs
@@ -18,7 +18,7 @@
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 -}
 
-{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts #-}
+{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, MultiWayIf #-}
 
 module Text.Pandoc.CrossRef.References.Blocks.CodeBlock where
 
@@ -38,29 +38,29 @@
 runCodeBlock :: Attr -> T.Text -> Either T.Text [Inline] -> WS (ReplacedResult Block)
 runCodeBlock (label, classes, attrs) code eCaption = do
   opts <- ask
-  case outFormat opts of
-    f --if used with listings package,nothing should be done
-      | isLatexFormat f, listings opts -> eCaption &
-        either
-          (const noReplaceNoRecurse)
-          (\caption -> replaceNoRecurse $
-            CodeBlock (label,classes,("caption",escapeLaTeX $ stringify caption):attrs) code)
+      --if used with listings package,nothing should be done
+  if  | isLatexFormat opts, listings opts ->
+          eCaption & either
+            (const noReplaceNoRecurse)
+            (\caption -> replaceNoRecurse $
+              CodeBlock (label,classes,("caption",escapeLaTeX $ stringify caption):attrs) code)
       --if not using listings, however, wrap it in a codelisting environment
-      | isLatexFormat f ->
-        replaceNoRecurse $ Div nullAttr [
-            RawBlock (Format "latex") "\\begin{codelisting}"
-          , Plain [
-              RawInline (Format "latex") "\\caption"
-            , Span nullAttr $ either (pure . Str) id eCaption
+      | isLatexFormat opts ->
+          replaceNoRecurse $ Div nullAttr [
+              RawBlock (Format "latex") $ "\\begin{codelisting}"
+            , Plain [
+                RawInline (Format "latex") "\\caption"
+              , Span nullAttr $ either (pure . Str) id eCaption
+              , RawInline (Format "latex") $ mkLaTeXLabel label
+              ]
+            , CodeBlock ("", classes, attrs) code
+            , RawBlock (Format "latex") "\\end{codelisting}"
             ]
-          , CodeBlock (label, classes, attrs) code
-          , RawBlock (Format "latex") "\\end{codelisting}"
-          ]
-    _ -> do
-      let cap = either (B.toList . B.text) id eCaption
-      idxStr <- replaceAttr (Right label) attrs cap SPfxLst
-      let caption' = applyTemplate idxStr cap $ listingTemplate opts
-      replaceNoRecurse $ Div (label, "listing":classes, []) [
-          mkCaption opts "Caption" caption'
-        , CodeBlock ("", classes, filter ((/="caption") . fst) $ setLabel opts idxStr attrs) code
-        ]
+      | otherwise -> do
+          let cap = either (B.toList . B.text) id eCaption
+          idxStr <- replaceAttr (Right label) attrs cap SPfxLst
+          let caption' = applyTemplate idxStr cap $ listingTemplate opts
+          replaceNoRecurse $ Div (label, "listing":classes, []) [
+              mkCaption opts "Caption" caption'
+            , CodeBlock ("", classes, filter ((/="caption") . fst) $ setLabel opts idxStr attrs) code
+            ]
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Header.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Header.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Header.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Header.hs
@@ -23,7 +23,7 @@
 module Text.Pandoc.CrossRef.References.Blocks.Header where
 
 import Control.Monad.Reader.Class
-import Control.Monad.State hiding (get, modify)
+import Control.Monad (when)
 import qualified Data.Map as M
 import qualified Data.Sequence as S
 import Data.Sequence (ViewR(..))
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Math.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Math.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Math.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Math.hs
@@ -37,7 +37,7 @@
 runBlockMath :: Attr -> T.Text -> WS (ReplacedResult Block)
 runBlockMath (label, cls, attrs) eq = do
   opts <- ask
-  if tableEqns opts && not (isLatexFormat (outFormat opts))
+  if tableEqns opts && not (isLatexFormat opts)
   then do
     (eq', idxStr) <- replaceEqn (label, cls, attrs) eq
     let mathfmt = if eqnBlockInlineMath opts then InlineMath else DisplayMath
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Subfigures.hs
@@ -18,7 +18,7 @@
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 -}
 
-{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, LambdaCase #-}
+{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts, LambdaCase, MultiWayIf #-}
 
 module Text.Pandoc.CrossRef.References.Blocks.Subfigures where
 
@@ -36,6 +36,7 @@
 import Lens.Micro
 import Lens.Micro.Mtl
 import Text.Pandoc.Shared (blocksToInlines)
+import Control.Monad ((<=<))
 
 import Text.Pandoc.CrossRef.References.Types
 import Text.Pandoc.CrossRef.References.Monad
@@ -81,27 +82,28 @@
   let mangledSubfigures = mangleSubfigure <$> st ^. refsAt PfxImg
       mangleSubfigure v = v{refIndex = refIndex lastRef, refSubfigure = Just $ refIndex v}
   refsAt PfxImg %= (<> mangledSubfigures)
-  case outFormat opts of
-    f | isLatexFormat f ->
-      replaceNoRecurse $ Div nullAttr $
-        [ RawBlock (Format "latex") "\\begin{pandoccrossrefsubfigures}" ]
-        <> cont <>
-        [ Para [RawInline (Format "latex") "\\caption["
-                  , Span nullAttr (removeFootnotes caption)
-                  , RawInline (Format "latex") "]"
-                  , Span nullAttr caption]
-        , RawBlock (Format "latex") $ mkLaTeXLabel label
-        , RawBlock (Format "latex") "\\end{pandoccrossrefsubfigures}"]
-    _ -> replaceNoRecurse
-      $ Figure (label, "subfigures":cls, setLabel opts idxStr attrs) (Caption Nothing [Para capt])
-      $ toTable opts cont
+  if  | isLatexFormat opts ->
+          replaceNoRecurse $ Div nullAttr $
+            [ RawBlock (Format "latex") "\\begin{pandoccrossrefsubfigures}" ]
+            <> cont <>
+            [ Para [RawInline (Format "latex") "\\caption["
+                      , Span nullAttr (removeFootnotes caption)
+                      , RawInline (Format "latex") "]"
+                      , Span nullAttr caption]
+            , RawBlock (Format "latex") $ mkLaTeXLabel label
+            , RawBlock (Format "latex") "\\end{pandoccrossrefsubfigures}"]
+      | otherwise ->
+          replaceNoRecurse
+            $ Figure (label, "subfigures":cls, setLabel opts idxStr attrs)
+                     (Caption Nothing [Para capt])
+            $ toTable opts cont
   where
     removeFootnotes = walk removeFootnote
     removeFootnote Note{} = Str ""
     removeFootnote x = x
     toTable :: Options -> [Block] -> [Block]
     toTable opts blks
-      | isLatexFormat $ outFormat opts = concatMap imagesToFigures blks
+      | isLatexFormat opts = concatMap imagesToFigures blks
       | subfigGrid opts = [simpleTable align (map ColWidth widths) (map (fmap pure . blkToRow) blks)]
       | otherwise = blks
       where
@@ -156,9 +158,9 @@
   let label' = normalizeLabel label
   idxStr <- replaceAttr label' attrs alt SPfxImg
   let alt' = applyTemplate idxStr alt $ figureTemplate opts
-  case outFormat opts of
-    f | isLatexFormat f -> pure $ latexSubFigure x label
-    _ -> pure [Image (label, cls, setLabel opts idxStr attrs) alt' tgt]
+  pure $ if isLatexFormat opts
+    then latexSubFigure x label
+    else [Image (label, cls, setLabel opts idxStr attrs) alt' tgt]
 replaceSubfig x = pure [x]
 
 latexSubFigure :: Inline -> T.Text -> [Inline]
@@ -207,12 +209,12 @@
         [Image (_, _, as) _ _] -> fattrs <> as
         _ -> fattrs
   idxStr <- replaceAttr label' attrs title SPfxImg
-  let title' = case outFormat opts of
-        f | isLatexFormat f -> title
-        _  -> applyTemplate idxStr title $ figureTemplate opts
+  let title'
+        | isLatexFormat opts = title
+        | otherwise = applyTemplate idxStr title $ figureTemplate opts
       caption' = Caption short (walkReplaceInlines title' title btitle:rest)
   replaceNoRecurse $
-    if subFigure && isLatexFormat (outFormat opts)
+    if subFigure && isLatexFormat opts
     then Plain $ latexSubFigure (head $ blocksToInlines content) label
     else Figure (label,cls,setLabel opts idxStr fattrs) caption' content
 runFigure _ _ _ _ = noReplaceNoRecurse
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Table.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Table.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Table.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Table.hs
@@ -37,16 +37,16 @@
 runTable (label, clss, attrs) mtattr short btitle rest colspec header cells foot = do
   opts <- ask
   idxStr <- replaceAttr (Right label) attrs title SPfxTbl
-  let title' =
-        case outFormat opts of
-            f | isLatexFormat f ->
-              RawInline (Format "latex") (mkLaTeXLabel label) : title
-            _  -> applyTemplate idxStr title $ tableTemplate opts
+  let title'
+        | isLatexFormat opts = RawInline (Format "latex") (mkLaTeXLabel label) : title
+        | otherwise = applyTemplate idxStr title $ tableTemplate opts
       caption' = Caption short (walkReplaceInlines title' title btitle:rest)
+      label' | isLatexFormat opts = ""
+             | otherwise = label
   replaceNoRecurse $ (mtattr &
     maybe
       (Table (label, clss, setLabel opts idxStr attrs))
-      (\tattr a b c d -> Div (label, clss, setLabel opts idxStr attrs) . pure . Table tattr a b c d)
+      (\tattr a b c d -> Div (label', clss, setLabel opts idxStr attrs) . pure . Table tattr a b c d)
     )
     caption' colspec header cells foot
   where title = blocksToInlines [btitle]
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Util.hs b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Util.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Util.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Blocks/Util.hs
@@ -24,12 +24,12 @@
 module Text.Pandoc.CrossRef.References.Blocks.Util where
 
 import Control.Monad.Reader.Class
-import Control.Monad.State hiding (get, modify)
 import qualified Data.Map as M
 import qualified Data.Text as T
 import Text.Pandoc.Definition
 import Text.Pandoc.Shared (stringify)
 import Text.Pandoc.Walk (walk)
+import Control.Monad (when)
 
 import Text.Read (readMaybe)
 
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/List.hs b/lib-internal/Text/Pandoc/CrossRef/References/List.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/List.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/List.hs
@@ -36,7 +36,7 @@
 import Text.Pandoc.CrossRef.Util.Template
 
 listOf :: [Block] -> WS [Block]
-listOf blocks = asks (isLatexFormat . outFormat) >>= \case
+listOf blocks = asks isLatexFormat >>= \case
   True -> pure blocks
   False -> case blocks of
     (RawBlock fmt "\\listoffigures":xs)
diff --git a/lib-internal/Text/Pandoc/CrossRef/References/Refs.hs b/lib-internal/Text/Pandoc/CrossRef/References/Refs.hs
--- a/lib-internal/Text/Pandoc/CrossRef/References/Refs.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/References/Refs.hs
@@ -32,6 +32,7 @@
 import Text.Pandoc.Builder
 import qualified Data.Sequence as S
 import Data.Sequence (ViewR(..))
+import Control.Monad (liftM2, join)
 
 import Debug.Trace
 import Lens.Micro.Mtl
@@ -63,9 +64,10 @@
             fromList (citationPrefix c) <> text ("@" <> citationId c)
               <> fromList (citationSuffix c)
     replaceRefs'' :: Options -> Prefix -> [Citation] -> WS [Inline]
-    replaceRefs'' opts = ($ opts) . flip $ case outFormat opts of
-                    f | isLatexFormat f -> replaceRefsLatex
-                    _                   -> replaceRefsOther
+    replaceRefs'' opts = ($ opts) . flip $
+      if isLatexFormat opts
+      then replaceRefsLatex
+      else replaceRefsOther
 replaceRefs x = return x
 
 pfxMap :: T.Text -> Maybe Prefix
diff --git a/lib-internal/Text/Pandoc/CrossRef/Util/ModifyMeta.hs b/lib-internal/Text/Pandoc/CrossRef/Util/ModifyMeta.hs
--- a/lib-internal/Text/Pandoc/CrossRef/Util/ModifyMeta.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/Util/ModifyMeta.hs
@@ -25,16 +25,16 @@
     ) where
 
 import Control.Monad.Writer
+import Control.Monad (when, unless)
 import qualified Data.Text as T
 import Text.Pandoc
 import Text.Pandoc.Builder hiding ((<>))
 import Text.Pandoc.CrossRef.Util.Meta
 import Text.Pandoc.CrossRef.Util.Options
-import Text.Pandoc.CrossRef.Util.Util
 
 modifyMeta :: Options -> Meta -> Meta
 modifyMeta opts meta
-  | isLatexFormat (outFormat opts)
+  | isLatexFormat opts
   = setMeta "header-includes"
       (headerInc $ lookupMeta "header-includes" meta)
       meta
diff --git a/lib-internal/Text/Pandoc/CrossRef/Util/Options.hs b/lib-internal/Text/Pandoc/CrossRef/Util/Options.hs
--- a/lib-internal/Text/Pandoc/CrossRef/Util/Options.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/Util/Options.hs
@@ -18,9 +18,12 @@
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 -}
 
-module Text.Pandoc.CrossRef.Util.Options (Options(..)) where
+{-# LANGUAGE OverloadedStrings#-}
+
+module Text.Pandoc.CrossRef.Util.Options (Options(..), isLatexFormat) where
 import Data.Text (Text)
 import Text.Pandoc.CrossRef.Util.Template
+import Text.Pandoc.CrossRef.Util.Util (isFormat)
 import Text.Pandoc.Definition
 
 data Options = Options { cref :: Bool
@@ -77,3 +80,6 @@
                        , setLabelAttribute :: Bool
                        , equationNumberTeX :: Text
                        }
+
+isLatexFormat :: Options -> Bool
+isLatexFormat = ((||) <$> (isFormat "latex") <*> (isFormat "beamer")) . outFormat
diff --git a/lib-internal/Text/Pandoc/CrossRef/Util/Util.hs b/lib-internal/Text/Pandoc/CrossRef/Util/Util.hs
--- a/lib-internal/Text/Pandoc/CrossRef/Util/Util.hs
+++ b/lib-internal/Text/Pandoc/CrossRef/Util/Util.hs
@@ -47,10 +47,6 @@
 isFormat fmt (Just (Format f)) = T.takeWhile (`notElem` ("+-" :: String)) f == fmt
 isFormat _ Nothing = False
 
-isLatexFormat :: Maybe Format -> Bool
-isLatexFormat = isFormat "latex" `or'` isFormat "beamer"
-  where a `or'` b = (||) <$> a <*> b
-
 capitalizeFirst :: T.Text -> T.Text
 capitalizeFirst t
   | Just (x, xs) <- T.uncons t = toUpper x `T.cons` xs
diff --git a/pandoc-crossref.cabal b/pandoc-crossref.cabal
--- a/pandoc-crossref.cabal
+++ b/pandoc-crossref.cabal
@@ -5,7 +5,7 @@
 -- see: https://github.com/sol/hpack
 
 name:           pandoc-crossref
-version:        0.3.16.0
+version:        0.3.17.0
 synopsis:       Pandoc filter for cross-references
 description:    pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.
 category:       Text
@@ -133,7 +133,7 @@
   build-depends:
       base >=4.11 && <5
     , mtl >=1.1 && <2.4
-    , pandoc >=3.0 && <3.2
+    , pandoc >=3.1.8 && <3.2
     , pandoc-crossref-internal
     , pandoc-types ==1.23.*
     , text >=1.2.2 && <2.1
@@ -171,13 +171,13 @@
     , containers >=0.1 && <0.7
     , data-default >=0.4 && <0.8
     , directory >=1 && <1.4
-    , filepath >=1.1 && <1.5
+    , filepath >=1.1 && <1.6
     , microlens >=0.4.12.0 && <0.5.0.0
     , microlens-ghc >=0.4.3.10 && <0.5.0.0
     , microlens-mtl >=0.2.0.1 && <0.3.0.0
     , microlens-th >=0.4.3.10 && <0.5.0.0
-    , mtl >=1.1 && <2.3
-    , pandoc >=3.0 && <3.2
+    , mtl >=1.1 && <2.4
+    , pandoc >=3.1.8 && <3.2
     , pandoc-types ==1.23.*
     , syb >=0.4 && <0.8
     , template-haskell >=2.7.0.0 && <3.0.0.0
@@ -194,11 +194,11 @@
   ghc-options: -Wall -threaded
   build-depends:
       base >=4.11 && <5
-    , deepseq ==1.4.*
+    , deepseq >=1.4 && <1.6
     , gitrev >=1.3.1 && <1.4
     , open-browser ==0.2.*
-    , optparse-applicative >=0.13 && <0.18
-    , pandoc >=3.0 && <3.2
+    , optparse-applicative >=0.13 && <0.19
+    , pandoc >=3.1.8 && <3.2
     , pandoc-crossref
     , pandoc-types ==1.23.*
     , template-haskell >=2.7.0.0 && <3.0.0.0
@@ -217,9 +217,9 @@
   build-depends:
       base >=4.11 && <5
     , directory >=1 && <1.4
-    , filepath >=1.1 && <1.5
+    , filepath >=1.1 && <1.6
     , hspec >=2.4.4 && <3
-    , pandoc >=3.0 && <3.2
+    , pandoc >=3.1.8 && <3.2
     , pandoc-crossref
     , pandoc-types ==1.23.*
     , text >=1.2.2 && <2.1
@@ -244,8 +244,8 @@
     , data-default >=0.4 && <0.8
     , hspec >=2.4.4 && <3
     , microlens >=0.4.12.0 && <0.5.0.0
-    , mtl >=1.1 && <2.3
-    , pandoc >=3.0 && <3.2
+    , mtl >=1.1 && <2.4
+    , pandoc >=3.1.8 && <3.2
     , pandoc-crossref
     , pandoc-crossref-internal
     , pandoc-types ==1.23.*
@@ -265,7 +265,7 @@
   build-depends:
       base >=4.11 && <5
     , criterion >=1.5.9.0 && <1.7
-    , pandoc >=3.0 && <3.2
+    , pandoc >=3.1.8 && <3.2
     , pandoc-crossref
     , pandoc-types ==1.23.*
     , text >=1.2.2 && <2.1
diff --git a/test/m2m/chapDelim/expect.tex b/test/m2m/chapDelim/expect.tex
--- a/test/m2m/chapDelim/expect.tex
+++ b/test/m2m/chapDelim/expect.tex
@@ -1,14 +1,9 @@
-\hypertarget{sec:section}{%
-\section{1 Section}\label{sec:section}}
+\section{1 Section}\label{sec:section}
 
-\hypertarget{sec:subsection}{%
-\subsection{1delim1 Subsection}\label{sec:subsection}}
+\subsection{1delim1 Subsection}\label{sec:subsection}
 
-\hypertarget{sec:subsubsection}{%
-\subsubsection{1delim1delim1 Subsubsection}\label{sec:subsubsection}}
+\subsubsection{1delim1delim1 Subsubsection}\label{sec:subsubsection}
 
-\hypertarget{sec:section-1}{%
-\section{2 Section}\label{sec:section-1}}
+\section{2 Section}\label{sec:section-1}
 
-\hypertarget{sec:subsubsection-1}{%
-\subsubsection{2delim1delim1 Subsubsection}\label{sec:subsubsection-1}}
+\subsubsection{2delim1delim1 Subsubsection}\label{sec:subsubsection-1}
diff --git a/test/m2m/delim/expect.tex b/test/m2m/delim/expect.tex
--- a/test/m2m/delim/expect.tex
+++ b/test/m2m/delim/expect.tex
@@ -13,20 +13,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/emptyChapterLabels/expect.tex b/test/m2m/emptyChapterLabels/expect.tex
--- a/test/m2m/emptyChapterLabels/expect.tex
+++ b/test/m2m/emptyChapterLabels/expect.tex
@@ -1,25 +1,18 @@
-\hypertarget{sec:section}{%
-\section{1 Section}\label{sec:section}}
+\section{1 Section}\label{sec:section}
 
-\hypertarget{sec:subsection}{%
-\subsection{1 Subsection}\label{sec:subsection}}
+\subsection{1 Subsection}\label{sec:subsection}
 
 \begin{figure}
-\hypertarget{fig:figure1}{%
 \centering
 \includegraphics{./image.png}
 \caption{Figure1}\label{fig:figure1}
-}
 \end{figure}
 
-\hypertarget{sec:subsubsection}{%
-\subsubsection{1.1 Subsubsection}\label{sec:subsubsection}}
+\subsubsection{1.1 Subsubsection}\label{sec:subsubsection}
 
-\hypertarget{sec:section-1}{%
-\section{2 Section}\label{sec:section-1}}
+\section{2 Section}\label{sec:section-1}
 
-\hypertarget{sec:subsubsection-1}{%
-\subsubsection{2.1.1 Subsubsection}\label{sec:subsubsection-1}}
+\subsubsection{2.1.1 Subsubsection}\label{sec:subsubsection-1}
 
 sec.~\ref{sec:subsubsection}
 
diff --git a/test/m2m/eqnBlockTemplate/expect.tex b/test/m2m/eqnBlockTemplate/expect.tex
--- a/test/m2m/eqnBlockTemplate/expect.tex
+++ b/test/m2m/eqnBlockTemplate/expect.tex
@@ -1,1 +1,1 @@
-\begin{equation}\protect\hypertarget{eq:1}{}{\int_0^x e^x dx}\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{\int_0^x e^x dx}\end{equation}
diff --git a/test/m2m/eqnInlineTemplate/expect.tex b/test/m2m/eqnInlineTemplate/expect.tex
--- a/test/m2m/eqnInlineTemplate/expect.tex
+++ b/test/m2m/eqnInlineTemplate/expect.tex
@@ -1,1 +1,1 @@
-\begin{equation}\protect\hypertarget{eq:1}{}{\int_0^x e^x dx}\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{\int_0^x e^x dx}\end{equation}
diff --git a/test/m2m/equationNumberLaTeX/expect.tex b/test/m2m/equationNumberLaTeX/expect.tex
--- a/test/m2m/equationNumberLaTeX/expect.tex
+++ b/test/m2m/equationNumberLaTeX/expect.tex
@@ -13,20 +13,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/equations-auto/expect.tex b/test/m2m/equations-auto/expect.tex
--- a/test/m2m/equations-auto/expect.tex
+++ b/test/m2m/equations-auto/expect.tex
@@ -15,20 +15,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/equations-tables-auto/expect.tex b/test/m2m/equations-tables-auto/expect.tex
--- a/test/m2m/equations-tables-auto/expect.tex
+++ b/test/m2m/equations-tables-auto/expect.tex
@@ -15,20 +15,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/equations-tables/expect.tex b/test/m2m/equations-tables/expect.tex
--- a/test/m2m/equations-tables/expect.tex
+++ b/test/m2m/equations-tables/expect.tex
@@ -13,20 +13,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/equations/expect.tex b/test/m2m/equations/expect.tex
--- a/test/m2m/equations/expect.tex
+++ b/test/m2m/equations/expect.tex
@@ -13,20 +13,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/label-precedence/expect.tex b/test/m2m/label-precedence/expect.tex
--- a/test/m2m/label-precedence/expect.tex
+++ b/test/m2m/label-precedence/expect.tex
@@ -1,46 +1,35 @@
-\hypertarget{first-section}{%
-\section{* First Section}\label{first-section}}
+\section{* First Section}\label{first-section}
 
 text
 
 \begin{figure}
-\hypertarget{fig:fig1}{%
 \centering
 \includegraphics{image.png}
 \caption{A figure}\label{fig:fig1}
-}
 \end{figure}
 
-\hypertarget{subsection}{%
-\subsection{*.A Subsection}\label{subsection}}
+\subsection{*.A Subsection}\label{subsection}
 
 other text
 
 \begin{figure}
-\hypertarget{fig:fig2}{%
 \centering
 \includegraphics{image.png}
 \caption{A figure with custom label}\label{fig:fig2}
-}
 \end{figure}
 
-\hypertarget{subsubsection}{%
-\subsubsection{*.A.A Subsubsection}\label{subsubsection}}
+\subsubsection{*.A.A Subsubsection}\label{subsubsection}
 
 text text text
 
-\hypertarget{custom-on-other-elements}{%
-\section{B Custom on other elements}\label{custom-on-other-elements}}
+\section{B Custom on other elements}\label{custom-on-other-elements}
 
 \begin{figure}
-\hypertarget{fig:fig3}{%
 \centering
 \includegraphics{fig.png}
 \caption{Figure}\label{fig:fig3}
-}
 \end{figure}
 
-\hypertarget{tbl:table}{}
 \begin{longtable}[]{@{}lll@{}}
 \caption{\label{tbl:table}Caption}\tabularnewline
 \toprule\noalign{}
@@ -57,6 +46,6 @@
 4 & 5 & 6 \\
 \end{longtable}
 
-\begin{equation}\protect\hypertarget{eq:equation}{}{y = e^x}\label{eq:equation}\end{equation}
+\begin{equation}\phantomsection\label{eq:equation}{y = e^x}\end{equation}
 
 fig.~\ref{fig:fig3} tbl.~\ref{tbl:table} eq.~\ref{eq:equation}
diff --git a/test/m2m/links-names/expect.tex b/test/m2m/links-names/expect.tex
--- a/test/m2m/links-names/expect.tex
+++ b/test/m2m/links-names/expect.tex
@@ -13,20 +13,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/links/expect.tex b/test/m2m/links/expect.tex
--- a/test/m2m/links/expect.tex
+++ b/test/m2m/links/expect.tex
@@ -13,20 +13,20 @@
 Some of those can be labelled:
 
 This is a test file with some referenced equations, line
-\begin{equation}\protect\hypertarget{eq:0}{}{ this }\label{eq:0}\end{equation}
+\begin{equation}\phantomsection\label{eq:0}{ this }\end{equation}
 
 Some equations might be inside of text,
-\begin{equation}\protect\hypertarget{eq:1}{}{ for example }\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{ for example }\end{equation}
 this one.
 
 Some equations might be on start of paragraphs:
 
-\begin{equation}\protect\hypertarget{eq:2}{}{ start }\label{eq:2}\end{equation}
-of paragraph.
+\begin{equation}\phantomsection\label{eq:2}{ start }\end{equation} of
+paragraph.
 
 Other might be on separate paragraphs of their own:
 
-\begin{equation}\protect\hypertarget{eq:3}{}{ separate }\label{eq:3}\end{equation}
+\begin{equation}\phantomsection\label{eq:3}{ separate }\end{equation}
 
 Then they can be referenced:
 
diff --git a/test/m2m/listOfTemplates-buillet-list/expect.tex b/test/m2m/listOfTemplates-buillet-list/expect.tex
--- a/test/m2m/listOfTemplates-buillet-list/expect.tex
+++ b/test/m2m/listOfTemplates-buillet-list/expect.tex
@@ -1,73 +1,55 @@
 \begin{figure}
-\hypertarget{fig:1}{%
 \centering
 \includegraphics{fig1.png}
 \caption{1}\label{fig:1}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:2}{%
 \centering
 \includegraphics{fig2.png}
 \caption{2}\label{fig:2}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:3}{%
 \centering
 \includegraphics{fig3.png}
 \caption{3}\label{fig:3}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:4}{%
 \centering
 \includegraphics{fig4.png}
 \caption{4}\label{fig:4}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:5}{%
 \centering
 \includegraphics{fig5.png}
 \caption{5}\label{fig:5}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:6}{%
 \centering
 \includegraphics{fig6.png}
 \caption{6}\label{fig:6}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:7}{%
 \centering
 \includegraphics{fig7.png}
 \caption{7}\label{fig:7}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:8}{%
 \centering
 \includegraphics{fig8.png}
 \caption{8}\label{fig:8}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:9}{%
 \centering
 \includegraphics{fig9.png}
 \caption{9}\label{fig:9}
-}
 \end{figure}
 
 \listoffigures
diff --git a/test/m2m/listOfTemplates-ord-list/expect.tex b/test/m2m/listOfTemplates-ord-list/expect.tex
--- a/test/m2m/listOfTemplates-ord-list/expect.tex
+++ b/test/m2m/listOfTemplates-ord-list/expect.tex
@@ -1,73 +1,55 @@
 \begin{figure}
-\hypertarget{fig:1}{%
 \centering
 \includegraphics{fig1.png}
 \caption{1}\label{fig:1}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:2}{%
 \centering
 \includegraphics{fig2.png}
 \caption{2}\label{fig:2}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:3}{%
 \centering
 \includegraphics{fig3.png}
 \caption{3}\label{fig:3}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:4}{%
 \centering
 \includegraphics{fig4.png}
 \caption{4}\label{fig:4}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:5}{%
 \centering
 \includegraphics{fig5.png}
 \caption{5}\label{fig:5}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:6}{%
 \centering
 \includegraphics{fig6.png}
 \caption{6}\label{fig:6}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:7}{%
 \centering
 \includegraphics{fig7.png}
 \caption{7}\label{fig:7}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:8}{%
 \centering
 \includegraphics{fig8.png}
 \caption{8}\label{fig:8}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:9}{%
 \centering
 \includegraphics{fig9.png}
 \caption{9}\label{fig:9}
-}
 \end{figure}
 
 \listoffigures
diff --git a/test/m2m/listOfTemplates/expect.tex b/test/m2m/listOfTemplates/expect.tex
--- a/test/m2m/listOfTemplates/expect.tex
+++ b/test/m2m/listOfTemplates/expect.tex
@@ -1,81 +1,61 @@
 \begin{figure}
-\hypertarget{fig:1}{%
 \centering
 \includegraphics{fig1.png}
 \caption{1}\label{fig:1}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:2}{%
 \centering
 \includegraphics{fig2.png}
 \caption{2}\label{fig:2}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:3}{%
 \centering
 \includegraphics{fig3.png}
 \caption{3}\label{fig:3}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:4}{%
 \centering
 \includegraphics{fig4.png}
 \caption{4}\label{fig:4}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:5}{%
 \centering
 \includegraphics{fig5.png}
 \caption{5}\label{fig:5}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:6}{%
 \centering
 \includegraphics{fig6.png}
 \caption{6}\label{fig:6}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:7}{%
 \centering
 \includegraphics{fig7.png}
 \caption{7}\label{fig:7}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:8}{%
 \centering
 \includegraphics{fig8.png}
 \caption{8}\label{fig:8}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:9}{%
 \centering
 \includegraphics{fig9.png}
 \caption{9}\label{fig:9}
-}
 \end{figure}
 
 \begin{codelisting}
 
-\caption{Listing caption 1}
+\caption{Listing caption 1}\label{lst:code1}
 
-\hypertarget{lst:code1}{%
-\label{lst:code1}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -87,10 +67,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 2}
+\caption{Listing caption 2}\label{lst:code2}
 
-\hypertarget{lst:code2}{%
-\label{lst:code2}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -102,10 +80,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 3}
+\caption{Listing caption 3}\label{lst:code3}
 
-\hypertarget{lst:code3}{%
-\label{lst:code3}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -117,10 +93,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 4}
+\caption{Listing caption 4}\label{lst:code4}
 
-\hypertarget{lst:code4}{%
-\label{lst:code4}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -132,7 +106,6 @@
 
 \begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}
 
-\hypertarget{tbl:mytable}{}
 \begin{longtable}[]{@{}lll@{}}
 \caption{\label{tbl:mytable}My table}\tabularnewline
 \toprule\noalign{}
@@ -149,7 +122,6 @@
 4 & 5 & 6 \\
 \end{longtable}
 
-\hypertarget{tbl:1}{}
 \begin{longtable}[]{@{}ll@{}}
 \caption{\label{tbl:1}Table}\tabularnewline
 \toprule\noalign{}
diff --git a/test/m2m/listing-captions-ids/expect.md b/test/m2m/listing-captions-ids/expect.md
--- a/test/m2m/listing-captions-ids/expect.md
+++ b/test/m2m/listing-captions-ids/expect.md
@@ -103,3 +103,19 @@
 main :: IO ()
 main = putStrLn "Hello World!"
 ```
+
+lst. 1
+
+lst. 2
+
+lst. 3
+
+lst. 4
+
+lst. 5
+
+lst. 6
+
+lst. 7
+
+lst. 8
diff --git a/test/m2m/listing-captions-ids/expect.tex b/test/m2m/listing-captions-ids/expect.tex
--- a/test/m2m/listing-captions-ids/expect.tex
+++ b/test/m2m/listing-captions-ids/expect.tex
@@ -2,10 +2,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 1}
+\caption{Listing caption 1}\label{lst:code1}
 
-\hypertarget{lst:code1}{%
-\label{lst:code1}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -17,10 +15,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 2}
+\caption{Listing caption 2}\label{lst:code2}
 
-\hypertarget{lst:code2}{%
-\label{lst:code2}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -32,10 +28,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 3}
+\caption{Listing caption 3}\label{lst:code3}
 
-\hypertarget{lst:code3}{%
-\label{lst:code3}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -47,10 +41,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 4}
+\caption{Listing caption 4}\label{lst:code4}
 
-\hypertarget{lst:code4}{%
-\label{lst:code4}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -82,10 +74,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 11}
+\caption{Listing caption 11}\label{lst:code11}
 
-\hypertarget{lst:code11}{%
-\label{lst:code11}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -97,10 +87,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 12}
+\caption{Listing caption 12}\label{lst:code12}
 
-\hypertarget{lst:code12}{%
-\label{lst:code12}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -112,10 +100,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 13}
+\caption{Listing caption 13}\label{lst:code13}
 
-\hypertarget{lst:code13}{%
-\label{lst:code13}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -127,10 +113,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 14}
+\caption{Listing caption 14}\label{lst:code14}
 
-\hypertarget{lst:code14}{%
-\label{lst:code14}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -159,3 +143,19 @@
 \NormalTok{main }\OtherTok{=} \FunctionTok{putStrLn} \StringTok{"Hello World!"}
 \end{Highlighting}
 \end{Shaded}
+
+lst.~\ref{lst:code1}
+
+lst.~\ref{lst:code2}
+
+lst.~\ref{lst:code3}
+
+lst.~\ref{lst:code4}
+
+lst.~\ref{lst:code11}
+
+lst.~\ref{lst:code12}
+
+lst.~\ref{lst:code13}
+
+lst.~\ref{lst:code14}
diff --git a/test/m2m/listing-captions-ids/input.md b/test/m2m/listing-captions-ids/input.md
--- a/test/m2m/listing-captions-ids/input.md
+++ b/test/m2m/listing-captions-ids/input.md
@@ -86,3 +86,20 @@
 main :: IO ()
 main = putStrLn "Hello World!"
 ```
+
+
+@lst:code1
+
+@lst:code2
+
+@lst:code3
+
+@lst:code4
+
+@lst:code11
+
+@lst:code12
+
+@lst:code13
+
+@lst:code14
diff --git a/test/m2m/loxItemTitle/expect.tex b/test/m2m/loxItemTitle/expect.tex
--- a/test/m2m/loxItemTitle/expect.tex
+++ b/test/m2m/loxItemTitle/expect.tex
@@ -1,81 +1,61 @@
 \begin{figure}
-\hypertarget{fig:1}{%
 \centering
 \includegraphics{fig1.png}
 \caption{1}\label{fig:1}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:2}{%
 \centering
 \includegraphics{fig2.png}
 \caption{2}\label{fig:2}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:3}{%
 \centering
 \includegraphics{fig3.png}
 \caption{3}\label{fig:3}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:4}{%
 \centering
 \includegraphics{fig4.png}
 \caption{4}\label{fig:4}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:5}{%
 \centering
 \includegraphics{fig5.png}
 \caption{5}\label{fig:5}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:6}{%
 \centering
 \includegraphics{fig6.png}
 \caption{6}\label{fig:6}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:7}{%
 \centering
 \includegraphics{fig7.png}
 \caption{7}\label{fig:7}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:8}{%
 \centering
 \includegraphics{fig8.png}
 \caption{8}\label{fig:8}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:9}{%
 \centering
 \includegraphics{fig9.png}
 \caption{9}\label{fig:9}
-}
 \end{figure}
 
 \begin{codelisting}
 
-\caption{Listing caption 1}
+\caption{Listing caption 1}\label{lst:code1}
 
-\hypertarget{lst:code1}{%
-\label{lst:code1}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -87,10 +67,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 2}
+\caption{Listing caption 2}\label{lst:code2}
 
-\hypertarget{lst:code2}{%
-\label{lst:code2}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -102,10 +80,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 3}
+\caption{Listing caption 3}\label{lst:code3}
 
-\hypertarget{lst:code3}{%
-\label{lst:code3}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -117,10 +93,8 @@
 
 \begin{codelisting}
 
-\caption{Listing caption 4}
+\caption{Listing caption 4}\label{lst:code4}
 
-\hypertarget{lst:code4}{%
-\label{lst:code4}}%
 \begin{Shaded}
 \begin{Highlighting}[]
 \OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
@@ -132,7 +106,6 @@
 
 \begin{center}\rule{0.5\linewidth}{0.5pt}\end{center}
 
-\hypertarget{tbl:mytable}{}
 \begin{longtable}[]{@{}lll@{}}
 \caption{\label{tbl:mytable}My table}\tabularnewline
 \toprule\noalign{}
@@ -149,7 +122,6 @@
 4 & 5 & 6 \\
 \end{longtable}
 
-\hypertarget{tbl:1}{}
 \begin{longtable}[]{@{}ll@{}}
 \caption{\label{tbl:1}Table}\tabularnewline
 \toprule\noalign{}
diff --git a/test/m2m/multiple-eqn-same-para/expect.tex b/test/m2m/multiple-eqn-same-para/expect.tex
--- a/test/m2m/multiple-eqn-same-para/expect.tex
+++ b/test/m2m/multiple-eqn-same-para/expect.tex
@@ -1,5 +1,5 @@
 Simple test
-\begin{equation}\protect\hypertarget{eq:1}{}{x=y}\label{eq:1}\end{equation}
-\begin{equation}\protect\hypertarget{eq:2}{}{x=y}\label{eq:2}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{x=y}\end{equation}
+\begin{equation}\phantomsection\label{eq:2}{x=y}\end{equation}
 
 eqns.~\ref{eq:1}, \ref{eq:2}
diff --git a/test/m2m/numberOverride/expect.tex b/test/m2m/numberOverride/expect.tex
--- a/test/m2m/numberOverride/expect.tex
+++ b/test/m2m/numberOverride/expect.tex
@@ -1,67 +1,49 @@
-\hypertarget{section}{%
-\section{1 Section}\label{section}}
+\section{1 Section}\label{section}
 
-\hypertarget{earlier-subsection}{%
-\subsection{1.1 Earlier Subsection}\label{earlier-subsection}}
+\subsection{1.1 Earlier Subsection}\label{earlier-subsection}
 
 \begin{figure}
-\hypertarget{fig:img1}{%
 \centering
 \includegraphics{img2.png}
 \caption{Image 1}\label{fig:img1}
-}
 \end{figure}
 
-\hypertarget{title-of-subsection}{%
-\subsection{1.6 Title of Subsection}\label{title-of-subsection}}
+\subsection{1.6 Title of Subsection}\label{title-of-subsection}
 
 \begin{figure}
-\hypertarget{fig:img2}{%
 \centering
 \includegraphics{img2.png}
 \caption{Image 1.6.2}\label{fig:img2}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:img3}{%
 \centering
 \includegraphics{img2.png}
 \caption{Image 1.6.100500}\label{fig:img3}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:img4}{%
 \centering
 \includegraphics{img2.png}
 \caption{Image 1.6.100501}\label{fig:img4}
-}
 \end{figure}
 
-\hypertarget{title-of-subsection-1}{%
-\subsection{1.7 Title of Subsection}\label{title-of-subsection-1}}
+\subsection{1.7 Title of Subsection}\label{title-of-subsection-1}
 
 \begin{figure}
-\hypertarget{fig:img21}{%
 \centering
 \includegraphics{img2.png}
 \caption{Image 1.7.1}\label{fig:img21}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:img31}{%
 \centering
 \includegraphics{img2.png}
 \caption{Image 1.7.100500}\label{fig:img31}
-}
 \end{figure}
 
 \begin{figure}
-\hypertarget{fig:img41}{%
 \centering
 \includegraphics{img2.png}
 \caption{Image 1.7.100501}\label{fig:img41}
-}
 \end{figure}
diff --git a/test/m2m/secLabels/expect.tex b/test/m2m/secLabels/expect.tex
--- a/test/m2m/secLabels/expect.tex
+++ b/test/m2m/secLabels/expect.tex
@@ -1,22 +1,16 @@
-\hypertarget{first-level-section}{%
-\section{a First Level Section}\label{first-level-section}}
+\section{a First Level Section}\label{first-level-section}
 
-\hypertarget{second-level-section}{%
-\subsection{a.a Second Level Section}\label{second-level-section}}
+\subsection{a.a Second Level Section}\label{second-level-section}
 
 \begin{figure}
-\hypertarget{fig:myfig}{%
 \centering
 \includegraphics{myfig.png}
 \caption{my figure}\label{fig:myfig}
-}
 \end{figure}
 
-\hypertarget{other-second-level-section}{%
 \subsection{a.b Other Second Level
-Section}\label{other-second-level-section}}
+Section}\label{other-second-level-section}
 
-\hypertarget{tbl:mytable}{}
 \begin{longtable}[]{@{}lll@{}}
 \caption{\label{tbl:mytable}My table}\tabularnewline
 \toprule\noalign{}
diff --git a/test/m2m/secLevelLabels/expect.tex b/test/m2m/secLevelLabels/expect.tex
--- a/test/m2m/secLevelLabels/expect.tex
+++ b/test/m2m/secLevelLabels/expect.tex
@@ -1,14 +1,11 @@
-\hypertarget{first-section}{%
-\section{A. First Section}\label{first-section}}
+\section{A. First Section}\label{first-section}
 
 text
 
-\hypertarget{subsection}{%
-\subsection{A.1) Subsection}\label{subsection}}
+\subsection{A.1) Subsection}\label{subsection}
 
 other text
 
-\hypertarget{subsubsection}{%
-\subsubsection{A.1.i Subsubsection}\label{subsubsection}}
+\subsubsection{A.1.i Subsubsection}\label{subsubsection}
 
 text text text
diff --git a/test/m2m/section-template/expect.tex b/test/m2m/section-template/expect.tex
--- a/test/m2m/section-template/expect.tex
+++ b/test/m2m/section-template/expect.tex
@@ -1,19 +1,13 @@
-\hypertarget{first-level-section}{%
-\section{Chapter 1. First Level Section}\label{first-level-section}}
+\section{Chapter 1. First Level Section}\label{first-level-section}
 
-\hypertarget{second-level-section}{%
 \subsection{Section 1.1. Second Level
-Section}\label{second-level-section}}
+Section}\label{second-level-section}
 
-\hypertarget{thrid-level-section}{%
 \subsubsection{Paragraph 1.1.1. Thrid Level
-Section}\label{thrid-level-section}}
+Section}\label{thrid-level-section}
 
-\hypertarget{fourth-level-section}{%
-\paragraph{1.1.1.1. Fourth Level Section}\label{fourth-level-section}}
+\paragraph{1.1.1.1. Fourth Level Section}\label{fourth-level-section}
 
-\hypertarget{fifth-level-section}{%
-\subparagraph{1.1.1.1.1. Fifth Level
-Section}\label{fifth-level-section}}
+\subparagraph{1.1.1.1.1. Fifth Level Section}\label{fifth-level-section}
 
 1.1.1.1.1.1. Sixth Level Section
diff --git a/test/m2m/setLabelAttribute/expect.md b/test/m2m/setLabelAttribute/expect.md
--- a/test/m2m/setLabelAttribute/expect.md
+++ b/test/m2m/setLabelAttribute/expect.md
@@ -27,3 +27,11 @@
 :::
 
 ## Section {#section-1 label="1.customLabel"}
+
+fig. 1.1
+
+eq. 1.1
+
+tbl. 1.1
+
+lst. 1.1
diff --git a/test/m2m/setLabelAttribute/expect.tex b/test/m2m/setLabelAttribute/expect.tex
--- a/test/m2m/setLabelAttribute/expect.tex
+++ b/test/m2m/setLabelAttribute/expect.tex
@@ -1,17 +1,13 @@
-\hypertarget{section}{%
-\section{Section}\label{section}}
+\section{Section}\label{section}
 
 \begin{figure}
-\hypertarget{fig:1}{%
 \centering
 \includegraphics{./image.png}
 \caption{Figure}\label{fig:1}
-}
 \end{figure}
 
-\begin{equation}\protect\hypertarget{eq:1}{}{equation}\label{eq:1}\end{equation}
+\begin{equation}\phantomsection\label{eq:1}{equation}\end{equation}
 
-\hypertarget{tbl:1}{}
 \begin{longtable}[]{@{}ll@{}}
 \caption{\label{tbl:1}Table}\tabularnewline
 \toprule\noalign{}
@@ -29,15 +25,20 @@
 
 \begin{codelisting}
 
-\caption{Code Listing}
+\caption{Code Listing}\label{lst:1}
 
-\hypertarget{lst:1}{%
-\label{lst:1}}%
 \begin{verbatim}
 code
 \end{verbatim}
 
 \end{codelisting}
 
-\hypertarget{section-1}{%
-\subsection{Section}\label{section-1}}
+\subsection{Section}\label{section-1}
+
+fig.~\ref{fig:1}
+
+eq.~\ref{eq:1}
+
+tbl.~\ref{tbl:1}
+
+lst.~\ref{lst:1}
diff --git a/test/m2m/setLabelAttribute/input.md b/test/m2m/setLabelAttribute/input.md
--- a/test/m2m/setLabelAttribute/input.md
+++ b/test/m2m/setLabelAttribute/input.md
@@ -23,3 +23,12 @@
 : Code Listing {#lst:1}
 
 ## Section {label="customLabel"}
+
+
+@fig:1
+
+@eq:1
+
+@tbl:1
+
+@lst:1
diff --git a/test/m2m/subfigures-one-row/expect.tex b/test/m2m/subfigures-one-row/expect.tex
--- a/test/m2m/subfigures-one-row/expect.tex
+++ b/test/m2m/subfigures-one-row/expect.tex
@@ -1,5 +1,4 @@
-\hypertarget{figures}{%
-\section{Figures}\label{figures}}
+\section{Figures}\label{figures}
 
 Regression test for
 \href{https://github.com/lierdakil/pandoc-crossref/issues/381}{\#381}
diff --git a/test/m2m/titlesInRefs/expect.tex b/test/m2m/titlesInRefs/expect.tex
--- a/test/m2m/titlesInRefs/expect.tex
+++ b/test/m2m/titlesInRefs/expect.tex
@@ -1,12 +1,9 @@
-\hypertarget{sec:section}{%
-\section{Section}\label{sec:section}}
+\section{Section}\label{sec:section}
 
 \begin{figure}
-\hypertarget{fig:figure}{%
 \centering
 \includegraphics{figure.png}
 \caption{A Figure}\label{fig:figure}
-}
 \end{figure}
 
 sec.~\ref{sec:section}
diff --git a/test/test-pandoc-crossref.hs b/test/test-pandoc-crossref.hs
--- a/test/test-pandoc-crossref.hs
+++ b/test/test-pandoc-crossref.hs
@@ -302,25 +302,24 @@
         it "Section labels" $
           headerWith ("sec:section_label1", [], []) 1 (text "Section")
             <> para (citeGen "sec:section_label" [1])
-            `test` "\\hypertarget{sec:section_label1}{%\n\\section{Section}\\label{sec:section_label1}}\n\nsec.~\\ref{sec:section_label1}"
+            `test` "\\section{Section}\\label{sec:section_label1}\n\nsec.~\\ref{sec:section_label1}"
 
         it "Image labels" $
           figure "img.png" "" "Title" Nothing "figure_label1"
             <> para (citeGen "fig:figure_label" [1])
-            `test` "\\begin{figure}\n\\hypertarget{fig:figure_label1}{%\n\\centering\n\\includegraphics{img.png}\n\\caption{Title}\\label{fig:figure_label1}\n}\n\\end{figure}\n\nfig.~\\ref{fig:figure_label1}"
+            `test` "\\begin{figure}\n\\centering\n\\includegraphics{img.png}\n\\caption{Title}\\label{fig:figure_label1}\n\\end{figure}\n\nfig.~\\ref{fig:figure_label1}"
 
         it "Eqn labels" $
           equation "x^2" "some_equation1"
             <> para (citeGen "eq:some_equation" [1])
-            `test` "\\begin{equation}\\protect\\hypertarget{eq:some_equation1}{}{x^2}\\label{eq:some_equation1}\\end{equation}\n\neq.~\\ref{eq:some_equation1}"
+            `test` "\\begin{equation}\\phantomsection\\label{eq:some_equation1}{x^2}\\end{equation}\n\neq.~\\ref{eq:some_equation1}"
 
 #ifdef FLAKY
         it "Tbl labels" $
           table' "A table" "some_table1"
             <> para (citeGen "tbl:some_table" [1])
             `test` concat (
-              [ "\\hypertarget{tbl:some_table1}{}\n"
-              , "\\begin{longtable}[]{@{}@{}}\n"
+              [ "\\begin{longtable}[]{@{}@{}}\n"
               , "\\caption{\\label{tbl:some_table1}A table}\\tabularnewline\n"
               , "\\toprule\\noalign{}\n"
               , "\\endfirsthead\n"
@@ -336,15 +335,15 @@
         it "Code block labels" $ do
           codeBlock' "A code block" "some_codeblock1"
             <> para (citeGen "lst:some_codeblock" [1])
-            `test` "\\begin{codelisting}\n\n\\caption{A code block}\n\n\\hypertarget{lst:some_codeblock1}{%\n\\label{lst:some_codeblock1}}%\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\OtherTok{main ::} \\DataTypeTok{IO}\\NormalTok{ ()}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:some_codeblock1}"
+            `test` "\\begin{codelisting}\n\n\\caption{A code block}\\label{lst:some_codeblock1}\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\OtherTok{main ::} \\DataTypeTok{IO}\\NormalTok{ ()}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:some_codeblock1}"
           codeBlock' "A code block with under_score" "some_codeblock1"
             <> para (citeGen "lst:some_codeblock" [1])
-            `test` "\\begin{codelisting}\n\n\\caption{A code block with under\\_score}\n\n\\hypertarget{lst:some_codeblock1}{%\n\\label{lst:some_codeblock1}}%\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\OtherTok{main ::} \\DataTypeTok{IO}\\NormalTok{ ()}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:some_codeblock1}"
+            `test` "\\begin{codelisting}\n\n\\caption{A code block with under\\_score}\\label{lst:some_codeblock1}\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\OtherTok{main ::} \\DataTypeTok{IO}\\NormalTok{ ()}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:some_codeblock1}"
           let test1 = test' $ setMeta "codeBlockCaptions" True nullMeta
               infixr 5 `test1`
           codeBlockForTable "some_codeblock1" <> paraText ": A code block"
             <> para (citeGen "lst:some_codeblock" [1])
-            `test1` "\\begin{codelisting}\n\n\\caption{A code block}\n\n\\hypertarget{lst:some_codeblock1}{%\n\\label{lst:some_codeblock1}}%\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\OtherTok{main ::} \\DataTypeTok{IO}\\NormalTok{ ()}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:some_codeblock1}"
+            `test1` "\\begin{codelisting}\n\n\\caption{A code block}\\label{lst:some_codeblock1}\n\n\\begin{Shaded}\n\\begin{Highlighting}[]\n\\OtherTok{main ::} \\DataTypeTok{IO}\\NormalTok{ ()}\n\\end{Highlighting}\n\\end{Shaded}\n\n\\end{codelisting}\n\nlst.~\\ref{lst:some_codeblock1}"
 
 citeGen :: T.Text -> [Int] -> Inlines
 citeGen p l = cite (mconcat $ map (cit . (p<>) . T.pack . show) l) $ text $
