@@ -347,7 +347,7 @@ options =
347347 (\arg opt ->
348348 case break (`elem` ":=") arg of
349349 (k,_:v) -> do
350− let newvars = (k, v) : optVariables opt
350+ let newvars = optVariables opt ++ [(k,v)]
351351 return opt{ optVariables = newvars }
352352 _ -> do
353353 hPutStrLn stderr $ "Could not parse `" ++ arg ++ "' as a key/value pair (k=v or k:v)"
@@ -358,7 +358,8 @@ options =
358358 , Option "c" ["css"]
359359 (ReqArg
360360 (\arg opt -> do
361− let newvars = ("css",arg) : optVariables opt
361+ -- add new link to end, so it is included in proper order
362+ let newvars = optVariables opt ++ [("css",arg)]
362363 return opt { optVariables = newvars,
363364 optStandalone = True })
364365 "URL")
@@ -368,7 +369,8 @@ options =
368369 (ReqArg
369370 (\arg opt -> do
370371 text <- readFile arg
371− let newvars = ("header-includes",text) : optVariables opt
372+ -- add new ones to end, so they're included in order specified
373+ let newvars = optVariables opt ++ [("header-includes",text)]
372374 return opt { optVariables = newvars,
373375 optStandalone = True })
374376 "FILENAME")
@@ -379,7 +381,8 @@ options =
379381 (\arg opt -> do
380382 text <- readFile arg
381383 let oldBefore = optBefore opt
382− return opt { optBefore = text : oldBefore })
384+ -- add new text to end, so it is included in proper order
385+ return opt { optBefore = oldBefore ++ [text] })
383386 "FILENAME")
384387 "" -- "File to include before document body"
385388
@@ -388,7 +391,8 @@ options =
388391 (\arg opt -> do
389392 text <- readFile arg
390393 let oldAfter = optAfter opt
391− return opt { optAfter = text : oldAfter })
394+ -- add new text to end, so it is included in proper order
395+ return opt { optAfter = oldAfter ++ [text]})
392396 "FILENAME")
393397 "" -- "File to include after document body"
394398
@@ -625,11 +629,7 @@ main = do
625629 variables' <- if writerName' == "s5" && standalone'
626630 then do
627631 inc <- s5HeaderIncludes
628− return $ case lookup "header-includes" variables of
629− Nothing -> ("header-includes", inc) : variables
630− Just a -> ("header-includes", a ++ inc) :
631− filter ((/= "header-includes") . fst)
632− variables
632+ return $ ("header-includes", inc) : variables
633633 else return variables
634634
635635 variables'' <- case mathMethod of