1

I am going back and forth between LaTeX and LyX.

I use TeXworks on WIndows 10 and have LyX 2.3 installed.

The major problem stems from using Figure and Subfigure (please see the codes below).

I tried everything to eliminate any extra packages that would make this conversion unnecessarily burdensome.

But I still have one problem with Figures and Subfigures.

When I export a LyX file to LaTeX(pdflatex), I get an error message here when compiling on TeXWorks:

\begin{figure}[hp] \centering \captionsetup{justification=centering} \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=1\linewidth,bb = 0 0 200 100, draft, type=eps]{sample.png}

So what I do is get rid of the following,

,bb = 0 0 200 100, draft, type=eps

And, I run the following, and it compiles on TeXworks fine.

\begin{figure}[hp] \centering \captionsetup{justification=centering} \begin{subfigure}{.5\textwidth} \centering \includegraphics[width=1\linewidth]{sample.png}

Question (1) Why do I need to do this every time I export from LyX to LaTeX(pdflatex)? Is there a way around this?

I have one other question when I do vice versa. Now, I am trying to import a TeXworks file to LyX, but I also have a trouble with a similar Figure and Subfigure set-up.

The error message I get in LyX is:

LaTeX Error: Cannot determine size of graphic in sample.png (no spe...)

So, when I trace back to where this code is in Texworks file, I notice I coded as:

\begin{figure}[hp] \centering \captionsetup{justification=centering} \begin{subfigure}{.5\textwidth} \centering \captionsetup{justification=centering} \includegraphics[width=1\linewidth]{sample1.jpg} \caption{sample1} \label{fig:sapmle1} \end{subfigure}\begin{subfigure}{.5\textwidth} \centering \captionsetup{justification=centering} \includegraphics[width=1\linewidth]{sample.png} \caption{sample} \label{fig:sample} \end{subfigure}\caption{sample 1 and sample} \label{fig:samples} \end{figure}

I do not understand why this is giving the size problem in LyX when I import this.

Question (2) Can someone help me this issue when I import a LaTeX file to LyX? I import as LaTeX(plain).

Thanks!

*** Error Image Added *** a sample error message from LyX

1 Answer 1

2

I am going back and forth between LaTeX and LyX.

Definitely a bad idea. Marry with LyX or TeXworks, whichever you like the most, or follow a LyX > LaTeX workflow, but without going back.

\includegraphics[ ... , type=eps]{sample.png}

Indeed, a PNG image should not have a type=eps option. Moreover, it should not show the extension .png, that is, even if you write sample.png as filename in the image configuration dialogue, the output should be:

\includegraphics[ ...]{sample}

In Lyx, I am able to produce the type=eps option only providing a fake image filename or including the above code for the image in a ERT (evil text red) box (Ctrl+L). Therefore, you should investigate why the image appear in LaTeX code as sample.png (with the extension). I would check first if sample.png really is in the working directory, if the extension is correct, specially if there is not a hide extension (I think that it is still the horrible default in Windows, so an apparent sample.png in the file manager could be really sample.png.exe or sample.png.eps), etc.

7
  • Fran, thanks for the response! I will try it without .png extension. But how about when I have a few images with .jpg extension? Don't I need to specify this extension in such case? Commented Sep 2, 2020 at 4:43
  • 1
    @FrankSwanton For pdflatex you can always suppress the .png, .jpg or .pdf extension, except if you have duplicate names with different extensions (e.g., foo.png, foo.jpg and foo.pdf) and then you have to specify which one must be used. Otherwise, LaTeX will search for any usable extension in a default order (that you can change, for instance, with` \DeclareGraphicsExtensions{.jpg, .png}` to use first the JPG versions as first option and not use PDF versions).
    – Fran
    Commented Sep 2, 2020 at 6:50
  • Fran, this is excellent. Thank you! Commented Sep 2, 2020 at 8:06
  • Fran, so do you think when I convert LaTeX from TeXworks to LyX, the eps option occurs, because LyX is having trouble reading in my initial LaTeX(plain)? I am trying to get rid of all the image extensions (e.g. .png, .jpg) to see if I import this cleaner version to LyX, it no longer would produce fake images. Do you think this is the problem? Commented Sep 2, 2020 at 8:11
  • Probably. But before of change your working document, make a test with minimal documents to be sure of where is the problem (it should be enough some like \documentclass{article} \usepackage{graphicx} \begin{document} Hello \includegraphics[width=1cm]{myimage} \end{document} and the same but with the extension)
    – Fran
    Commented Sep 2, 2020 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .