Don't want to get an extra char ahead of the latex block
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 92ac60b..55a342c 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -135,10 +135,13 @@
   regexp <- "(^|[^\\\\])([$][^$]*[^$\\\\]+[$]|[$][$][^$]*[^$\\\\]+[$][$])"
   latex <- character()
   while (grepl(regexp, kable_input)) {
-    block <- str_extract(kable_input, regexp)
+    block <- str_replace(str_extract(kable_input, regexp),
+                         regexp,
+                         "\\2")
+
     name <- paste0("latex", digest(block))
     latex[name] <- block
-    kable_input <- str_replace(kable_input, regexp, name)
+    kable_input <- str_replace(kable_input, regexp, paste0("\\1", name))
   }
   kable_attrs$extracted_latex <- latex
   attributes(kable_input) <- kable_attrs