Skip to content

Latex linebreak within includegraphics doesn't (always) work #10659

@lstngr

Description

@lstngr

I am experiencing an issue similar to #6114 on pandoc v3.6.3 (Lua 5.4) on Arch Linux,

$ pandoc -f latex -t native
\includegraphics[width=5cm]{abc.jpg}
^D
[ Para
    [ Image
        ( "" , [] , [ ( "width" , "5cm" ) ] )
        [ Str "image" ]
        ( "abc.jpg" , "" )
    ]
]


$ pandoc -f latex -t native  # from issue 6114, works as expected
\includegraphics[width=5cm]
{abc.jpg}
^D
[ Para
    [ Image
        ( "" , [] , [ ( "width" , "5cm" ) ] )
        [ Str "image" ]
        ( "abc.jpg" , "" )
    ]
]

$ pandoc -f latex -t native
\includegraphics[
width=5cm,
]{abc.jpg}
^D
Error at "source" (line 1, column 1):
unexpected Tok (line 1, column 1) (CtrlSeq "includegraphics") "\\includegraphics"
expecting end of input

$ pandoc -f latex -t native
\includegraphics[%
width=5cm,%
]{abc.jpg}
^D
Error at "source" (line 1, column 1):
unexpected Tok (line 1, column 1) (CtrlSeq "includegraphics") "\\includegraphics"
expecting end of input

# This does produce an output, but treats '%' signs as part of the filename rather than comments.
$ pandoc -f latex -t native
\includegraphics[width=5cm]{%
abc.jpg%
}
^D
[ Para
    [ Image
        ( "" , [] , [ ( "width" , "5cm" ) ] )
        [ Str "image" ]
        ( "%\nabc.jpg%\n" , "" )
    ]
]

Here's a minimal document in LaTeX showing that the syntax is valid

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=5cm]{example-image-a}

\includegraphics[
    width=5cm,
]{example-image-a}

\includegraphics[%
    width=5cm,%
]{example-image-a}

\includegraphics[width=5cm]{%
example-image-a%
}
\end{document}

In all afore-mentioned cases, I think the expected output should be

[ Para
    [ Image
        ( "" , [] , [ ( "width" , "5cm" ) ] )
        [ Str "image" ]
        ( "abc.jpg" , "" )
    ]
]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions