LaTeX reader: handle some width specifiers on table columns.

Currently we only handle the form `0.9\linewidth`.
Anything else would have to be converted to a percentage,
using some kind arbitrary assumptions about line widths.

See #3709.
This commit is contained in:
John MacFarlane 2017-06-01 12:08:28 +02:00
parent af6e8414c7
commit 9396f1fb67
2 changed files with 15 additions and 5 deletions

View file

@ -1451,14 +1451,24 @@ parseAligns = try $ do
<|> xAlign <|> mAlign <|> bAlign
let alignPrefix = char '>' >> braced
let alignSuffix = char '<' >> braced
let colWidth = try $ do
char '{'
ds <- many1 (oneOf "0123456789.")
spaces
string "\\linewidth"
char '}'
case safeRead ds of
Just w -> return w
Nothing -> return 0.0
let alignSpec = do
spaces
pref <- option "" alignPrefix
spaces
al <- alignChar
let parseWidth :: String -> Double
parseWidth _ = 0.00 -- TODO actually parse the width
width <- parseWidth <$> option "" braced
width <- colWidth <|> option 0.0 (do s <- braced
pos <- getPosition
report $ SkippedContent s pos
return 0.0)
spaces
suff <- option "" alignSuffix
return (al, width, (pref, suff))

View file

@ -57,7 +57,7 @@
\hline
\end{tabularx}
^D
[Table [] [AlignLeft,AlignCenter,AlignLeft] [0.0,0.0,0.0]
[Table [] [AlignLeft,AlignCenter,AlignLeft] [0.0,0.0,0.25]
[[Plain [Str "Column",Space,Str "Heading",Space,Str "1"]]
,[Plain [Str "Column",Space,Str "Heading",Space,Str "2"]]
,[Plain [Str "Column",Space,Str "Heading",Space,Str "3"]]]
@ -94,7 +94,7 @@
\hline
\end{tabularx}
^D
[Table [] [AlignLeft,AlignCenter,AlignLeft] [0.0,0.0,0.0]
[Table [] [AlignLeft,AlignCenter,AlignLeft] [0.25,0.0,0.25]
[[Plain [Str "Column",Space,Str "Heading",Space,Str "1"]]
,[Plain [Str "Column",Space,Str "Heading",Space,Str "2"]]
,[Plain [Str "Column",Space,Str "Heading",Space,Str "3"]]]