Multiple Reference Citation in order of appearance without Bibtex











up vote
0
down vote

favorite












This question is related to a question I asked earlier here. I wanted to cite references in order of appearance without Bibtex and the answer did exactly that. However, consider I have the following bibliography:



begin{thebibliography}{C}
bibitem{ref1}{AAAA}
bibitem{ref2}{BBBB}
bibitem{ref3}{CCCC}
bibitem{ref4}{DDDD}
bibitem{ref5}{EEEE}
end{thebibliography}


The code cite{ref2} and cite{ref3, ref4, ref5} will give [1] and [2,3,4] and what I want is [1] and [2-4] instead. How can I alter the code given in the previous answer? Note that using usepackage{cite} will output [1] and [4-6] which is not in the order of appearance.










share|improve this question


























    up vote
    0
    down vote

    favorite












    This question is related to a question I asked earlier here. I wanted to cite references in order of appearance without Bibtex and the answer did exactly that. However, consider I have the following bibliography:



    begin{thebibliography}{C}
    bibitem{ref1}{AAAA}
    bibitem{ref2}{BBBB}
    bibitem{ref3}{CCCC}
    bibitem{ref4}{DDDD}
    bibitem{ref5}{EEEE}
    end{thebibliography}


    The code cite{ref2} and cite{ref3, ref4, ref5} will give [1] and [2,3,4] and what I want is [1] and [2-4] instead. How can I alter the code given in the previous answer? Note that using usepackage{cite} will output [1] and [4-6] which is not in the order of appearance.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      This question is related to a question I asked earlier here. I wanted to cite references in order of appearance without Bibtex and the answer did exactly that. However, consider I have the following bibliography:



      begin{thebibliography}{C}
      bibitem{ref1}{AAAA}
      bibitem{ref2}{BBBB}
      bibitem{ref3}{CCCC}
      bibitem{ref4}{DDDD}
      bibitem{ref5}{EEEE}
      end{thebibliography}


      The code cite{ref2} and cite{ref3, ref4, ref5} will give [1] and [2,3,4] and what I want is [1] and [2-4] instead. How can I alter the code given in the previous answer? Note that using usepackage{cite} will output [1] and [4-6] which is not in the order of appearance.










      share|improve this question













      This question is related to a question I asked earlier here. I wanted to cite references in order of appearance without Bibtex and the answer did exactly that. However, consider I have the following bibliography:



      begin{thebibliography}{C}
      bibitem{ref1}{AAAA}
      bibitem{ref2}{BBBB}
      bibitem{ref3}{CCCC}
      bibitem{ref4}{DDDD}
      bibitem{ref5}{EEEE}
      end{thebibliography}


      The code cite{ref2} and cite{ref3, ref4, ref5} will give [1] and [2,3,4] and what I want is [1] and [2-4] instead. How can I alter the code given in the previous answer? Note that using usepackage{cite} will output [1] and [4-6] which is not in the order of appearance.







      bibliographies






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 12 hours ago









      Lod

      222




      222






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The implementation in Sorting bibliography in order of appearance without Bibtex naively assumed that the argument of citation is always only a single key. That is a valid assumption for the standard implementation of cite, but not for the implementation of cite's cite.



          The following simple extension should also deal with comma-separated lists. The only difference is the introduction of a CSV loop in citation and the resulting move of the core of the macro to citation@i.



          documentclass[british]{article}
          usepackage[T1]{fontenc}
          usepackage[utf8]{inputenc}
          usepackage{babel}
          usepackage{cite}
          usepackage{etoolbox}
          usepackage{hyperref}

          makeatletter
          newcommand*{lodbib@citeorder}{}
          newcommand*{lodbib@notcited}{}% catch entries that were not cited

          % macro in aux file
          defcitation{%
          forcsvlist{citation@i}}

          defcitation@i#1{%
          ifinlist{#1}{lodbib@citeorder}
          {}
          {listxadd{lodbib@citeorder}{#1}}}

          letltxorig@lbibitem@lbibitem
          letltxorig@bibitem@bibitem

          % save bibitems
          def@lbibitem[#1]#2#3{%
          csdef{lodbib@savedlabel@#2}{#1}%
          @bibitem{#2}{#3}}

          def@bibitem#1#2{%
          xifinlist{#1}{lodbib@citeorder}
          {}
          {listadd{lodbib@notcited}{#1}}%
          csdef{lodbib@savedentry@#1}{#2}}

          renewenvironment{thebibliography}[1]
          {settowidthlabelwidth{@biblabel{#1}}}
          {def@noitemerr
          {@latex@warning{Empty `thebibliography' environment}}%
          section*{refname}%
          @mkboth{MakeUppercaserefname}{MakeUppercaserefname}%
          list{@biblabel{@arabicc@enumiv}}%
          {leftmarginlabelwidth
          advanceleftmarginlabelsep
          @openbib@code
          usecounter{enumiv}%
          letp@enumiv@empty
          renewcommandtheenumiv{@arabicc@enumiv}}%
          sloppy
          clubpenalty4000
          @clubpenalty clubpenalty
          widowpenalty4000%
          sfcode`.@m
          lodbib@biblistloop
          endlist}

          deflodbib@biblistloop{%
          forlistloop{lodbib@bibitem}{lodbib@citeorder}%
          ifdefvoid{lodbib@notcited}
          {}
          {forlistloop{lodbib@bibitem}{lodbib@notcited}}}

          deflodbib@bibitem#1{%
          ifcsundef{lodbib@savedlabel@#1}
          {ltxorig@bibitem{#1}}
          {ltxorig@lbibitem[csuse{lodbib@savedlabel@#1}]{#1}}%
          csuse{lodbib@savedentry@#1}}
          makeatother


          begin{document}
          cite{ref2} and cite{ref3, ref4, ref5}

          begin{thebibliography}{C}
          bibitem{ref1}{AAAA}
          bibitem{ref2}{BBBB}
          bibitem{ref3}{CCCC}
          bibitem{ref4}{DDDD}
          bibitem{ref5}{EEEE}
          end{thebibliography}

          cite{ref2}
          end{document}


          The citations read "[1] and [2–4]"






          share|improve this answer























            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',
            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%2f461829%2fmultiple-reference-citation-in-order-of-appearance-without-bibtex%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








            up vote
            1
            down vote



            accepted










            The implementation in Sorting bibliography in order of appearance without Bibtex naively assumed that the argument of citation is always only a single key. That is a valid assumption for the standard implementation of cite, but not for the implementation of cite's cite.



            The following simple extension should also deal with comma-separated lists. The only difference is the introduction of a CSV loop in citation and the resulting move of the core of the macro to citation@i.



            documentclass[british]{article}
            usepackage[T1]{fontenc}
            usepackage[utf8]{inputenc}
            usepackage{babel}
            usepackage{cite}
            usepackage{etoolbox}
            usepackage{hyperref}

            makeatletter
            newcommand*{lodbib@citeorder}{}
            newcommand*{lodbib@notcited}{}% catch entries that were not cited

            % macro in aux file
            defcitation{%
            forcsvlist{citation@i}}

            defcitation@i#1{%
            ifinlist{#1}{lodbib@citeorder}
            {}
            {listxadd{lodbib@citeorder}{#1}}}

            letltxorig@lbibitem@lbibitem
            letltxorig@bibitem@bibitem

            % save bibitems
            def@lbibitem[#1]#2#3{%
            csdef{lodbib@savedlabel@#2}{#1}%
            @bibitem{#2}{#3}}

            def@bibitem#1#2{%
            xifinlist{#1}{lodbib@citeorder}
            {}
            {listadd{lodbib@notcited}{#1}}%
            csdef{lodbib@savedentry@#1}{#2}}

            renewenvironment{thebibliography}[1]
            {settowidthlabelwidth{@biblabel{#1}}}
            {def@noitemerr
            {@latex@warning{Empty `thebibliography' environment}}%
            section*{refname}%
            @mkboth{MakeUppercaserefname}{MakeUppercaserefname}%
            list{@biblabel{@arabicc@enumiv}}%
            {leftmarginlabelwidth
            advanceleftmarginlabelsep
            @openbib@code
            usecounter{enumiv}%
            letp@enumiv@empty
            renewcommandtheenumiv{@arabicc@enumiv}}%
            sloppy
            clubpenalty4000
            @clubpenalty clubpenalty
            widowpenalty4000%
            sfcode`.@m
            lodbib@biblistloop
            endlist}

            deflodbib@biblistloop{%
            forlistloop{lodbib@bibitem}{lodbib@citeorder}%
            ifdefvoid{lodbib@notcited}
            {}
            {forlistloop{lodbib@bibitem}{lodbib@notcited}}}

            deflodbib@bibitem#1{%
            ifcsundef{lodbib@savedlabel@#1}
            {ltxorig@bibitem{#1}}
            {ltxorig@lbibitem[csuse{lodbib@savedlabel@#1}]{#1}}%
            csuse{lodbib@savedentry@#1}}
            makeatother


            begin{document}
            cite{ref2} and cite{ref3, ref4, ref5}

            begin{thebibliography}{C}
            bibitem{ref1}{AAAA}
            bibitem{ref2}{BBBB}
            bibitem{ref3}{CCCC}
            bibitem{ref4}{DDDD}
            bibitem{ref5}{EEEE}
            end{thebibliography}

            cite{ref2}
            end{document}


            The citations read "[1] and [2–4]"






            share|improve this answer



























              up vote
              1
              down vote



              accepted










              The implementation in Sorting bibliography in order of appearance without Bibtex naively assumed that the argument of citation is always only a single key. That is a valid assumption for the standard implementation of cite, but not for the implementation of cite's cite.



              The following simple extension should also deal with comma-separated lists. The only difference is the introduction of a CSV loop in citation and the resulting move of the core of the macro to citation@i.



              documentclass[british]{article}
              usepackage[T1]{fontenc}
              usepackage[utf8]{inputenc}
              usepackage{babel}
              usepackage{cite}
              usepackage{etoolbox}
              usepackage{hyperref}

              makeatletter
              newcommand*{lodbib@citeorder}{}
              newcommand*{lodbib@notcited}{}% catch entries that were not cited

              % macro in aux file
              defcitation{%
              forcsvlist{citation@i}}

              defcitation@i#1{%
              ifinlist{#1}{lodbib@citeorder}
              {}
              {listxadd{lodbib@citeorder}{#1}}}

              letltxorig@lbibitem@lbibitem
              letltxorig@bibitem@bibitem

              % save bibitems
              def@lbibitem[#1]#2#3{%
              csdef{lodbib@savedlabel@#2}{#1}%
              @bibitem{#2}{#3}}

              def@bibitem#1#2{%
              xifinlist{#1}{lodbib@citeorder}
              {}
              {listadd{lodbib@notcited}{#1}}%
              csdef{lodbib@savedentry@#1}{#2}}

              renewenvironment{thebibliography}[1]
              {settowidthlabelwidth{@biblabel{#1}}}
              {def@noitemerr
              {@latex@warning{Empty `thebibliography' environment}}%
              section*{refname}%
              @mkboth{MakeUppercaserefname}{MakeUppercaserefname}%
              list{@biblabel{@arabicc@enumiv}}%
              {leftmarginlabelwidth
              advanceleftmarginlabelsep
              @openbib@code
              usecounter{enumiv}%
              letp@enumiv@empty
              renewcommandtheenumiv{@arabicc@enumiv}}%
              sloppy
              clubpenalty4000
              @clubpenalty clubpenalty
              widowpenalty4000%
              sfcode`.@m
              lodbib@biblistloop
              endlist}

              deflodbib@biblistloop{%
              forlistloop{lodbib@bibitem}{lodbib@citeorder}%
              ifdefvoid{lodbib@notcited}
              {}
              {forlistloop{lodbib@bibitem}{lodbib@notcited}}}

              deflodbib@bibitem#1{%
              ifcsundef{lodbib@savedlabel@#1}
              {ltxorig@bibitem{#1}}
              {ltxorig@lbibitem[csuse{lodbib@savedlabel@#1}]{#1}}%
              csuse{lodbib@savedentry@#1}}
              makeatother


              begin{document}
              cite{ref2} and cite{ref3, ref4, ref5}

              begin{thebibliography}{C}
              bibitem{ref1}{AAAA}
              bibitem{ref2}{BBBB}
              bibitem{ref3}{CCCC}
              bibitem{ref4}{DDDD}
              bibitem{ref5}{EEEE}
              end{thebibliography}

              cite{ref2}
              end{document}


              The citations read "[1] and [2–4]"






              share|improve this answer

























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                The implementation in Sorting bibliography in order of appearance without Bibtex naively assumed that the argument of citation is always only a single key. That is a valid assumption for the standard implementation of cite, but not for the implementation of cite's cite.



                The following simple extension should also deal with comma-separated lists. The only difference is the introduction of a CSV loop in citation and the resulting move of the core of the macro to citation@i.



                documentclass[british]{article}
                usepackage[T1]{fontenc}
                usepackage[utf8]{inputenc}
                usepackage{babel}
                usepackage{cite}
                usepackage{etoolbox}
                usepackage{hyperref}

                makeatletter
                newcommand*{lodbib@citeorder}{}
                newcommand*{lodbib@notcited}{}% catch entries that were not cited

                % macro in aux file
                defcitation{%
                forcsvlist{citation@i}}

                defcitation@i#1{%
                ifinlist{#1}{lodbib@citeorder}
                {}
                {listxadd{lodbib@citeorder}{#1}}}

                letltxorig@lbibitem@lbibitem
                letltxorig@bibitem@bibitem

                % save bibitems
                def@lbibitem[#1]#2#3{%
                csdef{lodbib@savedlabel@#2}{#1}%
                @bibitem{#2}{#3}}

                def@bibitem#1#2{%
                xifinlist{#1}{lodbib@citeorder}
                {}
                {listadd{lodbib@notcited}{#1}}%
                csdef{lodbib@savedentry@#1}{#2}}

                renewenvironment{thebibliography}[1]
                {settowidthlabelwidth{@biblabel{#1}}}
                {def@noitemerr
                {@latex@warning{Empty `thebibliography' environment}}%
                section*{refname}%
                @mkboth{MakeUppercaserefname}{MakeUppercaserefname}%
                list{@biblabel{@arabicc@enumiv}}%
                {leftmarginlabelwidth
                advanceleftmarginlabelsep
                @openbib@code
                usecounter{enumiv}%
                letp@enumiv@empty
                renewcommandtheenumiv{@arabicc@enumiv}}%
                sloppy
                clubpenalty4000
                @clubpenalty clubpenalty
                widowpenalty4000%
                sfcode`.@m
                lodbib@biblistloop
                endlist}

                deflodbib@biblistloop{%
                forlistloop{lodbib@bibitem}{lodbib@citeorder}%
                ifdefvoid{lodbib@notcited}
                {}
                {forlistloop{lodbib@bibitem}{lodbib@notcited}}}

                deflodbib@bibitem#1{%
                ifcsundef{lodbib@savedlabel@#1}
                {ltxorig@bibitem{#1}}
                {ltxorig@lbibitem[csuse{lodbib@savedlabel@#1}]{#1}}%
                csuse{lodbib@savedentry@#1}}
                makeatother


                begin{document}
                cite{ref2} and cite{ref3, ref4, ref5}

                begin{thebibliography}{C}
                bibitem{ref1}{AAAA}
                bibitem{ref2}{BBBB}
                bibitem{ref3}{CCCC}
                bibitem{ref4}{DDDD}
                bibitem{ref5}{EEEE}
                end{thebibliography}

                cite{ref2}
                end{document}


                The citations read "[1] and [2–4]"






                share|improve this answer














                The implementation in Sorting bibliography in order of appearance without Bibtex naively assumed that the argument of citation is always only a single key. That is a valid assumption for the standard implementation of cite, but not for the implementation of cite's cite.



                The following simple extension should also deal with comma-separated lists. The only difference is the introduction of a CSV loop in citation and the resulting move of the core of the macro to citation@i.



                documentclass[british]{article}
                usepackage[T1]{fontenc}
                usepackage[utf8]{inputenc}
                usepackage{babel}
                usepackage{cite}
                usepackage{etoolbox}
                usepackage{hyperref}

                makeatletter
                newcommand*{lodbib@citeorder}{}
                newcommand*{lodbib@notcited}{}% catch entries that were not cited

                % macro in aux file
                defcitation{%
                forcsvlist{citation@i}}

                defcitation@i#1{%
                ifinlist{#1}{lodbib@citeorder}
                {}
                {listxadd{lodbib@citeorder}{#1}}}

                letltxorig@lbibitem@lbibitem
                letltxorig@bibitem@bibitem

                % save bibitems
                def@lbibitem[#1]#2#3{%
                csdef{lodbib@savedlabel@#2}{#1}%
                @bibitem{#2}{#3}}

                def@bibitem#1#2{%
                xifinlist{#1}{lodbib@citeorder}
                {}
                {listadd{lodbib@notcited}{#1}}%
                csdef{lodbib@savedentry@#1}{#2}}

                renewenvironment{thebibliography}[1]
                {settowidthlabelwidth{@biblabel{#1}}}
                {def@noitemerr
                {@latex@warning{Empty `thebibliography' environment}}%
                section*{refname}%
                @mkboth{MakeUppercaserefname}{MakeUppercaserefname}%
                list{@biblabel{@arabicc@enumiv}}%
                {leftmarginlabelwidth
                advanceleftmarginlabelsep
                @openbib@code
                usecounter{enumiv}%
                letp@enumiv@empty
                renewcommandtheenumiv{@arabicc@enumiv}}%
                sloppy
                clubpenalty4000
                @clubpenalty clubpenalty
                widowpenalty4000%
                sfcode`.@m
                lodbib@biblistloop
                endlist}

                deflodbib@biblistloop{%
                forlistloop{lodbib@bibitem}{lodbib@citeorder}%
                ifdefvoid{lodbib@notcited}
                {}
                {forlistloop{lodbib@bibitem}{lodbib@notcited}}}

                deflodbib@bibitem#1{%
                ifcsundef{lodbib@savedlabel@#1}
                {ltxorig@bibitem{#1}}
                {ltxorig@lbibitem[csuse{lodbib@savedlabel@#1}]{#1}}%
                csuse{lodbib@savedentry@#1}}
                makeatother


                begin{document}
                cite{ref2} and cite{ref3, ref4, ref5}

                begin{thebibliography}{C}
                bibitem{ref1}{AAAA}
                bibitem{ref2}{BBBB}
                bibitem{ref3}{CCCC}
                bibitem{ref4}{DDDD}
                bibitem{ref5}{EEEE}
                end{thebibliography}

                cite{ref2}
                end{document}


                The citations read "[1] and [2–4]"







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 12 hours ago

























                answered 12 hours ago









                moewe

                83.2k8107320




                83.2k8107320






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461829%2fmultiple-reference-citation-in-order-of-appearance-without-bibtex%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

                    サソリ

                    広島県道265号伴広島線

                    Accessing regular linux commands in Huawei's Dopra Linux