Empty captions with KOMA-script, maybe together with hyperref












2















I like captions to normally have a colon, but not when the caption is empty. This is something that the package caption does automatically, so



documentclass{scrartcl}

usepackage{caption}
usepackage{hyperref}

begin{document}
begin{figure}
caption{Test}
caption{}
end{figure}
end{document}


yields



enter image description here



which is what I want. But I want to use KOMA captions without the caption package, and then I get "Figure 1: Test / Figure 2:" with the extra colon at the end. How can I patch it to make it as I want?



I need a solution that works together with hyperref. An answer to this earlier question where hyperref isn't involved doesn't work with it, so it may complicate things.










share|improve this question





























    2















    I like captions to normally have a colon, but not when the caption is empty. This is something that the package caption does automatically, so



    documentclass{scrartcl}

    usepackage{caption}
    usepackage{hyperref}

    begin{document}
    begin{figure}
    caption{Test}
    caption{}
    end{figure}
    end{document}


    yields



    enter image description here



    which is what I want. But I want to use KOMA captions without the caption package, and then I get "Figure 1: Test / Figure 2:" with the extra colon at the end. How can I patch it to make it as I want?



    I need a solution that works together with hyperref. An answer to this earlier question where hyperref isn't involved doesn't work with it, so it may complicate things.










    share|improve this question



























      2












      2








      2








      I like captions to normally have a colon, but not when the caption is empty. This is something that the package caption does automatically, so



      documentclass{scrartcl}

      usepackage{caption}
      usepackage{hyperref}

      begin{document}
      begin{figure}
      caption{Test}
      caption{}
      end{figure}
      end{document}


      yields



      enter image description here



      which is what I want. But I want to use KOMA captions without the caption package, and then I get "Figure 1: Test / Figure 2:" with the extra colon at the end. How can I patch it to make it as I want?



      I need a solution that works together with hyperref. An answer to this earlier question where hyperref isn't involved doesn't work with it, so it may complicate things.










      share|improve this question
















      I like captions to normally have a colon, but not when the caption is empty. This is something that the package caption does automatically, so



      documentclass{scrartcl}

      usepackage{caption}
      usepackage{hyperref}

      begin{document}
      begin{figure}
      caption{Test}
      caption{}
      end{figure}
      end{document}


      yields



      enter image description here



      which is what I want. But I want to use KOMA captions without the caption package, and then I get "Figure 1: Test / Figure 2:" with the extra colon at the end. How can I patch it to make it as I want?



      I need a solution that works together with hyperref. An answer to this earlier question where hyperref isn't involved doesn't work with it, so it may complicate things.







      hyperref captions koma-script






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 6 at 14:43







      pst

















      asked Feb 3 at 10:56









      pstpst

      2,591824




      2,591824






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Well I think it is really the better way to typeset and measure the caption instead of looking at the tokens:



           documentclass{scrartcl}

          usepackage{hyperref}

          usepackage{xpatch}
          makeatletter
          patchcmd@@makecaption{begingroup}
          {%
          settowidth{@tempdima}{#3}%
          ifdim@tempdima=0pt
          defcaptionformat{}%
          fi
          begingroup
          }{}{fail}

          begin{document}
          begin{figure}
          caption{Test}
          caption{}
          caption{ }
          caption{new}
          end{figure}
          end{document}


          Without hyperref this will also remove the colons for the caption with a space in it, but with hyperref this space counts.



          enter image description here






          share|improve this answer


























          • You still have the usepackage{caption} line in there, which is what actually fixes it!

            – pst
            Feb 3 at 12:11











          • Oh. Sorry. Will have to check again.

            – Ulrike Fischer
            Feb 3 at 12:13











          • @pst I adapted the code.

            – Ulrike Fischer
            Feb 3 at 12:24











          • Great! So now this is a better answer to my old question as well. For posterity I think it would be better if I remove that question and change this to be both without or with hyperref. What do you think?

            – pst
            Feb 3 at 12:33











          • Are you OK with me doing as I suggested @Ulrike? (I don't want to go ahead otherwise since that question has an answer from you.)

            – pst
            Feb 6 at 11:06













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473159%2fempty-captions-with-koma-script-maybe-together-with-hyperref%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Well I think it is really the better way to typeset and measure the caption instead of looking at the tokens:



           documentclass{scrartcl}

          usepackage{hyperref}

          usepackage{xpatch}
          makeatletter
          patchcmd@@makecaption{begingroup}
          {%
          settowidth{@tempdima}{#3}%
          ifdim@tempdima=0pt
          defcaptionformat{}%
          fi
          begingroup
          }{}{fail}

          begin{document}
          begin{figure}
          caption{Test}
          caption{}
          caption{ }
          caption{new}
          end{figure}
          end{document}


          Without hyperref this will also remove the colons for the caption with a space in it, but with hyperref this space counts.



          enter image description here






          share|improve this answer


























          • You still have the usepackage{caption} line in there, which is what actually fixes it!

            – pst
            Feb 3 at 12:11











          • Oh. Sorry. Will have to check again.

            – Ulrike Fischer
            Feb 3 at 12:13











          • @pst I adapted the code.

            – Ulrike Fischer
            Feb 3 at 12:24











          • Great! So now this is a better answer to my old question as well. For posterity I think it would be better if I remove that question and change this to be both without or with hyperref. What do you think?

            – pst
            Feb 3 at 12:33











          • Are you OK with me doing as I suggested @Ulrike? (I don't want to go ahead otherwise since that question has an answer from you.)

            – pst
            Feb 6 at 11:06


















          3














          Well I think it is really the better way to typeset and measure the caption instead of looking at the tokens:



           documentclass{scrartcl}

          usepackage{hyperref}

          usepackage{xpatch}
          makeatletter
          patchcmd@@makecaption{begingroup}
          {%
          settowidth{@tempdima}{#3}%
          ifdim@tempdima=0pt
          defcaptionformat{}%
          fi
          begingroup
          }{}{fail}

          begin{document}
          begin{figure}
          caption{Test}
          caption{}
          caption{ }
          caption{new}
          end{figure}
          end{document}


          Without hyperref this will also remove the colons for the caption with a space in it, but with hyperref this space counts.



          enter image description here






          share|improve this answer


























          • You still have the usepackage{caption} line in there, which is what actually fixes it!

            – pst
            Feb 3 at 12:11











          • Oh. Sorry. Will have to check again.

            – Ulrike Fischer
            Feb 3 at 12:13











          • @pst I adapted the code.

            – Ulrike Fischer
            Feb 3 at 12:24











          • Great! So now this is a better answer to my old question as well. For posterity I think it would be better if I remove that question and change this to be both without or with hyperref. What do you think?

            – pst
            Feb 3 at 12:33











          • Are you OK with me doing as I suggested @Ulrike? (I don't want to go ahead otherwise since that question has an answer from you.)

            – pst
            Feb 6 at 11:06
















          3












          3








          3







          Well I think it is really the better way to typeset and measure the caption instead of looking at the tokens:



           documentclass{scrartcl}

          usepackage{hyperref}

          usepackage{xpatch}
          makeatletter
          patchcmd@@makecaption{begingroup}
          {%
          settowidth{@tempdima}{#3}%
          ifdim@tempdima=0pt
          defcaptionformat{}%
          fi
          begingroup
          }{}{fail}

          begin{document}
          begin{figure}
          caption{Test}
          caption{}
          caption{ }
          caption{new}
          end{figure}
          end{document}


          Without hyperref this will also remove the colons for the caption with a space in it, but with hyperref this space counts.



          enter image description here






          share|improve this answer















          Well I think it is really the better way to typeset and measure the caption instead of looking at the tokens:



           documentclass{scrartcl}

          usepackage{hyperref}

          usepackage{xpatch}
          makeatletter
          patchcmd@@makecaption{begingroup}
          {%
          settowidth{@tempdima}{#3}%
          ifdim@tempdima=0pt
          defcaptionformat{}%
          fi
          begingroup
          }{}{fail}

          begin{document}
          begin{figure}
          caption{Test}
          caption{}
          caption{ }
          caption{new}
          end{figure}
          end{document}


          Without hyperref this will also remove the colons for the caption with a space in it, but with hyperref this space counts.



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 3 at 12:24

























          answered Feb 3 at 11:21









          Ulrike FischerUlrike Fischer

          192k8299682




          192k8299682













          • You still have the usepackage{caption} line in there, which is what actually fixes it!

            – pst
            Feb 3 at 12:11











          • Oh. Sorry. Will have to check again.

            – Ulrike Fischer
            Feb 3 at 12:13











          • @pst I adapted the code.

            – Ulrike Fischer
            Feb 3 at 12:24











          • Great! So now this is a better answer to my old question as well. For posterity I think it would be better if I remove that question and change this to be both without or with hyperref. What do you think?

            – pst
            Feb 3 at 12:33











          • Are you OK with me doing as I suggested @Ulrike? (I don't want to go ahead otherwise since that question has an answer from you.)

            – pst
            Feb 6 at 11:06





















          • You still have the usepackage{caption} line in there, which is what actually fixes it!

            – pst
            Feb 3 at 12:11











          • Oh. Sorry. Will have to check again.

            – Ulrike Fischer
            Feb 3 at 12:13











          • @pst I adapted the code.

            – Ulrike Fischer
            Feb 3 at 12:24











          • Great! So now this is a better answer to my old question as well. For posterity I think it would be better if I remove that question and change this to be both without or with hyperref. What do you think?

            – pst
            Feb 3 at 12:33











          • Are you OK with me doing as I suggested @Ulrike? (I don't want to go ahead otherwise since that question has an answer from you.)

            – pst
            Feb 6 at 11:06



















          You still have the usepackage{caption} line in there, which is what actually fixes it!

          – pst
          Feb 3 at 12:11





          You still have the usepackage{caption} line in there, which is what actually fixes it!

          – pst
          Feb 3 at 12:11













          Oh. Sorry. Will have to check again.

          – Ulrike Fischer
          Feb 3 at 12:13





          Oh. Sorry. Will have to check again.

          – Ulrike Fischer
          Feb 3 at 12:13













          @pst I adapted the code.

          – Ulrike Fischer
          Feb 3 at 12:24





          @pst I adapted the code.

          – Ulrike Fischer
          Feb 3 at 12:24













          Great! So now this is a better answer to my old question as well. For posterity I think it would be better if I remove that question and change this to be both without or with hyperref. What do you think?

          – pst
          Feb 3 at 12:33





          Great! So now this is a better answer to my old question as well. For posterity I think it would be better if I remove that question and change this to be both without or with hyperref. What do you think?

          – pst
          Feb 3 at 12:33













          Are you OK with me doing as I suggested @Ulrike? (I don't want to go ahead otherwise since that question has an answer from you.)

          – pst
          Feb 6 at 11:06







          Are you OK with me doing as I suggested @Ulrike? (I don't want to go ahead otherwise since that question has an answer from you.)

          – pst
          Feb 6 at 11:06




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473159%2fempty-captions-with-koma-script-maybe-together-with-hyperref%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?