Skip to content
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

Subcaption issues #88

Closed
clason opened this issue Sep 21, 2019 · 6 comments
Closed

Subcaption issues #88

clason opened this issue Sep 21, 2019 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@clason
Copy link
Contributor

clason commented Sep 21, 2019

I noticed two small issues with parsing subcaption labels in document symbols (and completion) only:

  1. If I have subfigures, the containing figure incorrectly gets the label from the first subfigure (i.e., Figure 1a instead of Figure 1). The problem is that the figure label is not the first label in the containing environment (since captions are usually below figures); if the caption is moved to the top of the environment, it is picked up correctly. Note that this is an issue in parsing the aux file; the caption is still correctly linked to the figure environment, e.g., in the LocationLink of GotoDefinition.

  2. subtables do not seem to be supported (the environment isn't autocompleted, and they don't appear in the symbol list). EDIT: This is an easy fix, see Subcaption fix #89

Brief example, in case it's useful:

\documentclass{article}
\usepackage{subcaption}

\begin{document}

\begin{figure}
    \begin{subfigure}{0.4\textwidth}
        \caption{A subfigure}
        \label{fig1a}
    \end{subfigure}
    \begin{subfigure}{0.4\textwidth}
        \caption{Another subfigure}
        \label{fig1b}
    \end{subfigure}
    \caption{A figure}
    \label{fig1}
\end{figure}

\begin{table}
    \begin{subtable}{0.4\textwidth}
        \caption{A subtable}
        \label{tab1a}
    \end{subtable}
    \begin{subtable}{0.4\textwidth}
        \caption{Another subtable}
        \label{tab1b}
    \end{subtable}
    \caption{A table}
    \label{tab1}
\end{table}

\end{document}

Aux file:

\relax
\providecommand\hyper@newdestlabel[2]{}
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
\global\let\oldcontentsline\contentsline
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
\global\let\oldnewlabel\newlabel
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
\AtEndDocument{\ifx\hyper@anchor\@undefined
\let\contentsline\oldcontentsline
\let\newlabel\oldnewlabel
\fi}
\fi}
\global\let\hyper@last\relax
\gdef\HyperFirstAtBeginDocument#1{#1}
\providecommand\HyField@AuxAddToFields[1]{}
\providecommand\HyField@AuxAddToCoFields[2]{}
\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
\newlabel{fig1a}{{1a}{1}{A subfigure\relax }{figure.caption.1}{}}
\newlabel{sub@fig1a}{{a}{1}{A subfigure\relax }{figure.caption.1}{}}
\newlabel{fig1b}{{1b}{1}{Another subfigure\relax }{figure.caption.1}{}}
\newlabel{sub@fig1b}{{b}{1}{Another subfigure\relax }{figure.caption.1}{}}
\@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces A figure\relax }}{1}{figure.caption.    1}\protected@file@percent }
\newlabel{fig1}{{1}{1}{A figure\relax }{figure.caption.1}{}}
\newlabel{tab1a}{{1a}{1}{A subtable\relax }{table.caption.2}{}}
\newlabel{sub@tab1a}{{a}{1}{A subtable\relax }{table.caption.2}{}}
\newlabel{tab1b}{{1b}{1}{Another subtable\relax }{table.caption.2}{}}
\newlabel{sub@tab1b}{{b}{1}{Another subtable\relax }{table.caption.2}{}}
\@writefile{lot}{\contentsline {table}{\numberline {1}{\ignorespaces A table\relax }}{1}{table.caption.       2}\protected@file@percent }
\newlabel{tab1}{{1}{1}{A table\relax }{table.caption.2}{}}
@pfoerster pfoerster self-assigned this Sep 21, 2019
@pfoerster pfoerster added the bug Something isn't working label Sep 21, 2019
@pfoerster
Copy link
Member

If I have subfigures, the containing figure incorrectly gets the label from the first subfigure (i.e., Figure 1a instead of Figure 1). The problem is that the figure label is not the first label in the containing environment (since captions are usually below figures); if the caption is moved to the top of the environment, it is picked up correctly. Note that this is an issue in parsing the aux file; the caption is still correctly linked to the figure environment, e.g., in the LocationLink of GotoDefinition.

@clason Can you try the latest commit on the master branch? 484332b and 72acbc9 should fix the issue.

the environment isn't autocompleted

@efoerster needs to have a look at this one.

@clason
Copy link
Contributor Author

clason commented Sep 21, 2019

@clason Can you try the latest commit on the master branch? 484332b and 72acbc9 should fix the issue.

I already have, and they do! 👍

@efoerster needs to have a look at this one.

Probably just missing an entry in data.json.

@pfoerster
Copy link
Member

Probably just missing an entry in data.json.

Yes, there is definitely missing an entry in data.json, which is automatically generated by a script.

@clason
Copy link
Contributor Author

clason commented Sep 21, 2019

Ah, that's where they went. I remember looking at them in the texlab repo a while ago.

The subfigure/subfloat environments are a bit weird in how they are defined by subcaption; I'm surprised a script could extract them from the style files at all... (But I don't see how subfigure made it and subtable didn't -- maybe the script is picking the first up from some other package?)

@efoerster
Copy link
Member

The subfigure/subfloat environments are a bit weird in how they are defined by subcaption; I'm surprised a script could extract them from the style files at all... (But I don't see how subfigure made it and subtable didn't -- maybe the script is picking the first up from some other package?)

The script is not picking it up because subtable does not appear in the source code files of the subcaption package. We scan the source code and check the command candidates with the TeX engine afterwards. However, I just added it manually for now. It should now work with d8264a2.

@clason
Copy link
Contributor Author

clason commented Sep 28, 2019

The script is not picking it up because subtable does not appear in the source code files of the subcaption package.

Yeah, it's a bit weird. It also doesn't define subfigure, but that one does appear in another style file in the same directory (which is an old, deprecated, version of caption that is still distributed for compatibility).

However, I just added it manually for now. It should now work with d8264a2.

So it does, thank you!

@clason clason closed this as completed Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants