-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
\newcommand-like definitions with 'bare' command name #4470
Comments
My understanding is: In pandoc/src/Text/Pandoc/Readers/LaTeX.hs Lines 1897 to 1906 in d6f9715
But this pandoc/src/Text/Pandoc/Readers/LaTeX.hs Lines 401 to 406 in d6f9715
i.e. |
I tried moving Perhaps this could be worked around by having a state variable that gets set when a token is read, and reset when |
Oddly, the technique I sketched didn't work at all. On a crude benchmark: doMacro after getting token: 1.4s doMacro before getting token: 1.56s doMacro conditional on a state variable, ensuring that we don't run it too many times: 1.8s! I can't really explain this. |
here's the code I tried: diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 23b68361e..44a9771f9 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -159,6 +159,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
, sLogMessages :: [LogMessage]
, sIdentifiers :: Set.Set String
, sVerbatimMode :: Bool
+ , sExpanded :: Bool
, sCaption :: Maybe Inlines
, sInListItem :: Bool
, sInTableCell :: Bool
@@ -178,6 +179,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
, sLogMessages = []
, sIdentifiers = Set.empty
, sVerbatimMode = False
+ , sExpanded = False
, sCaption = Nothing
, sInListItem = False
, sInTableCell = False
@@ -401,8 +403,12 @@ untoken (Tok _ _ t) = t
satisfyTok :: PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok f =
try $ do
+ expanded <- sExpanded <$> getState
+ unless expanded $ do
+ doMacros 0 -- apply macros on remaining input stream
+ updateState $ \st -> st{ sExpanded = True }
res <- tokenPrim (T.unpack . untoken) updatePos matcher
- doMacros 0 -- apply macros on remaining input stream
+ updateState $ \st -> st{ sExpanded = False }
return res
where matcher t | f t = Just t
| otherwise = Nothing |
When defining a LaTeX macro, subsequent occurrences of
\renewcommand
or\providecommand
with 'bare' command name (i.e. not enclosed in{ }
) fails because the (bare) command name gets wrongly expanded.Input:
Expected output:
Actual output (with 2.1.3 from git master):
The text was updated successfully, but these errors were encountered: