Is there a shortcut to draw 30 degree bond angle increments in ChemFig?












2















I really like the facility in ChemFig to choose the bond angle in 45 degree increments by specifying an integer, instead of the angle directly: chemfig{-[1]}. Right now, I'm drawing a bunch of hydrocarbon molecules, and I think a 30 degree increment on the bond angle looks better. Of course, I can specify each angle using the [:angle] syntax, but that's too much typing! Is there any comparable shortcut for 30 degree angles?



documentclass{standalone}
usepackage{chemfig}
begin{document}
chemfig{-[:30]-[:330]-[:30]-[:330]}
end{document}









share|improve this question



























    2















    I really like the facility in ChemFig to choose the bond angle in 45 degree increments by specifying an integer, instead of the angle directly: chemfig{-[1]}. Right now, I'm drawing a bunch of hydrocarbon molecules, and I think a 30 degree increment on the bond angle looks better. Of course, I can specify each angle using the [:angle] syntax, but that's too much typing! Is there any comparable shortcut for 30 degree angles?



    documentclass{standalone}
    usepackage{chemfig}
    begin{document}
    chemfig{-[:30]-[:330]-[:30]-[:330]}
    end{document}









    share|improve this question

























      2












      2








      2








      I really like the facility in ChemFig to choose the bond angle in 45 degree increments by specifying an integer, instead of the angle directly: chemfig{-[1]}. Right now, I'm drawing a bunch of hydrocarbon molecules, and I think a 30 degree increment on the bond angle looks better. Of course, I can specify each angle using the [:angle] syntax, but that's too much typing! Is there any comparable shortcut for 30 degree angles?



      documentclass{standalone}
      usepackage{chemfig}
      begin{document}
      chemfig{-[:30]-[:330]-[:30]-[:330]}
      end{document}









      share|improve this question














      I really like the facility in ChemFig to choose the bond angle in 45 degree increments by specifying an integer, instead of the angle directly: chemfig{-[1]}. Right now, I'm drawing a bunch of hydrocarbon molecules, and I think a 30 degree increment on the bond angle looks better. Of course, I can specify each angle using the [:angle] syntax, but that's too much typing! Is there any comparable shortcut for 30 degree angles?



      documentclass{standalone}
      usepackage{chemfig}
      begin{document}
      chemfig{-[:30]-[:330]-[:30]-[:330]}
      end{document}






      chemfig






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 22 '15 at 11:38









      darthbithdarthbith

      5,49332049




      5,49332049






















          4 Answers
          4






          active

          oldest

          votes


















          2














          The idea is to create a new macro setangleincrement which allow to set the increment of the angle when [<number>] follows a bond. It could be a new feature for the next version...



          documentclass{article}
          usepackage{chemfig}
          makeatletter
          CF@defsetangleincrement{defCF@angle@increment}
          setangleincrement{45}% default value
          defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
          ifx@empty#1@empty%
          let#2CF@default@angle
          else
          if:expandafternoexpand@car#1@nil
          if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
          pgfmathsetmacro#2{CF@previous@angle+expandafter@gobble@gobble#1}%
          else
          expandafterdefexpandafter#2expandafter{@gobble#1}%
          fi
          else
          pgfmathsetmacro#2{#1*CF@angle@increment}%
          fi% puis normalise l'angle entre 0 et 360
          ifdimifdim#2pt<z@-fi#2pt>360pt pgfmathsetmacro #2{#2-360*floor(#2/360)}fi% si |#2|>360
          fi
          }
          makeatother
          begin{document}
          45 degres increment: chemfig{-[9]-[-1]-[1]-[-1]}

          setangleincrement{30}
          30 degres increment: chemfig{-[1]-[-1]-[1]-[-1]}
          end{document}


          enter image description here






          share|improve this answer































            3














            You can use setchemfig.



            enter image description here



            documentclass{article}
            usepackage{chemfig}
            begin{document}
            setchemfig{angle increment=30}
            chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
            end{document}





            share|improve this answer








            New contributor




            GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




























              1














              Depending on the use case I'd use submols:



              documentclass{standalone}
              usepackage{chemfig}
              definesubmol{r}{-[::-60]}
              definesubmol{l}{-[::60]}
              begin{document}
              chemfig{[:30]-!r!l!r!l}
              end{document}





              share|improve this answer































                0














                Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-defining the code that processes the bond angle specification.
                (PS I'm rather new at doing this sort of thing, so improvement suggestions are welcome!)



                Somewhat arbitrarily, I'll choose letters a through l (lowercase ell) to represent the angles 0 through 330 degrees. Then, we just need to add some code to the bottom of the macro where the processing of the integer specifications takes place to process the letters instead of numbers:



                defCF@set@bondangle#1#2{
                ifx@empty#1@empty%
                let#2CF@default@angle
                else
                if
                ...% In the code I've removed, it reads the explicit angle specification
                else % Here is the new code
                ifnum0<0#1relax% First check if the input is an integer or a letter
                ifnum#1>7% If an integer, process as before. This code is unchanged
                pgfmathparse{#1-floor(#1/8)*8}
                ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                else
                edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                fi
                else% Otherwise, process the letter into an integer and assign the proper angle
                edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                fi%
                fi
                fi
                }


                Note that only letters a through l are supported, and this can probably break in a number of unforeseen ways, including (I think) negative integer inputs (but those didn't work in the original implementation anyways). The line to check whether the input is an integer or letter is from here: How to check if the value of a parameter is a number? (see egreg's answer), and the code to check the case containing a letter was suggested by David Carlisle.



                MWE:



                documentclass{standalone}
                usepackage{chemfig}
                makeatletter
                defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                ifx@empty#1@empty%
                let#2CF@default@angle
                else
                if:expandafternoexpand@car#1@nil
                if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                pgfmathparse{CF@previous@angle+expandafter@gobble@gobble#1}%
                let#2pgfmathresult
                else
                expandafterdefexpandafter#2expandafter{@gobble#1}%
                fi% puis normalise l'angle entre 0 et 360
                ifdimifdim#2pt<z@-fi#2pt>360pt % si |#2|>360
                pgfmathparse{#2-360*floor(#2/360)}%
                ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+360}fi
                let#2pgfmathresult
                else
                ifdim#2pt<z@
                pgfmathparse{#2+360}%
                let#2pgfmathresult
                fi
                fi
                else
                ifnum0<0#1relax%
                ifnum#1>7
                pgfmathparse{#1-floor(#1/8)*8}%
                ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                else
                edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                fi
                else
                edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                fi%
                fi
                fi
                }
                makeatother

                begin{document}
                chemfig{-[:30]-[l]-[b]-[:330]}
                end{document}


                enter image description here






                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',
                  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%2f246368%2fis-there-a-shortcut-to-draw-30-degree-bond-angle-increments-in-chemfig%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  2














                  The idea is to create a new macro setangleincrement which allow to set the increment of the angle when [<number>] follows a bond. It could be a new feature for the next version...



                  documentclass{article}
                  usepackage{chemfig}
                  makeatletter
                  CF@defsetangleincrement{defCF@angle@increment}
                  setangleincrement{45}% default value
                  defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                  ifx@empty#1@empty%
                  let#2CF@default@angle
                  else
                  if:expandafternoexpand@car#1@nil
                  if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                  pgfmathsetmacro#2{CF@previous@angle+expandafter@gobble@gobble#1}%
                  else
                  expandafterdefexpandafter#2expandafter{@gobble#1}%
                  fi
                  else
                  pgfmathsetmacro#2{#1*CF@angle@increment}%
                  fi% puis normalise l'angle entre 0 et 360
                  ifdimifdim#2pt<z@-fi#2pt>360pt pgfmathsetmacro #2{#2-360*floor(#2/360)}fi% si |#2|>360
                  fi
                  }
                  makeatother
                  begin{document}
                  45 degres increment: chemfig{-[9]-[-1]-[1]-[-1]}

                  setangleincrement{30}
                  30 degres increment: chemfig{-[1]-[-1]-[1]-[-1]}
                  end{document}


                  enter image description here






                  share|improve this answer




























                    2














                    The idea is to create a new macro setangleincrement which allow to set the increment of the angle when [<number>] follows a bond. It could be a new feature for the next version...



                    documentclass{article}
                    usepackage{chemfig}
                    makeatletter
                    CF@defsetangleincrement{defCF@angle@increment}
                    setangleincrement{45}% default value
                    defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                    ifx@empty#1@empty%
                    let#2CF@default@angle
                    else
                    if:expandafternoexpand@car#1@nil
                    if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                    pgfmathsetmacro#2{CF@previous@angle+expandafter@gobble@gobble#1}%
                    else
                    expandafterdefexpandafter#2expandafter{@gobble#1}%
                    fi
                    else
                    pgfmathsetmacro#2{#1*CF@angle@increment}%
                    fi% puis normalise l'angle entre 0 et 360
                    ifdimifdim#2pt<z@-fi#2pt>360pt pgfmathsetmacro #2{#2-360*floor(#2/360)}fi% si |#2|>360
                    fi
                    }
                    makeatother
                    begin{document}
                    45 degres increment: chemfig{-[9]-[-1]-[1]-[-1]}

                    setangleincrement{30}
                    30 degres increment: chemfig{-[1]-[-1]-[1]-[-1]}
                    end{document}


                    enter image description here






                    share|improve this answer


























                      2












                      2








                      2







                      The idea is to create a new macro setangleincrement which allow to set the increment of the angle when [<number>] follows a bond. It could be a new feature for the next version...



                      documentclass{article}
                      usepackage{chemfig}
                      makeatletter
                      CF@defsetangleincrement{defCF@angle@increment}
                      setangleincrement{45}% default value
                      defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                      ifx@empty#1@empty%
                      let#2CF@default@angle
                      else
                      if:expandafternoexpand@car#1@nil
                      if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                      pgfmathsetmacro#2{CF@previous@angle+expandafter@gobble@gobble#1}%
                      else
                      expandafterdefexpandafter#2expandafter{@gobble#1}%
                      fi
                      else
                      pgfmathsetmacro#2{#1*CF@angle@increment}%
                      fi% puis normalise l'angle entre 0 et 360
                      ifdimifdim#2pt<z@-fi#2pt>360pt pgfmathsetmacro #2{#2-360*floor(#2/360)}fi% si |#2|>360
                      fi
                      }
                      makeatother
                      begin{document}
                      45 degres increment: chemfig{-[9]-[-1]-[1]-[-1]}

                      setangleincrement{30}
                      30 degres increment: chemfig{-[1]-[-1]-[1]-[-1]}
                      end{document}


                      enter image description here






                      share|improve this answer













                      The idea is to create a new macro setangleincrement which allow to set the increment of the angle when [<number>] follows a bond. It could be a new feature for the next version...



                      documentclass{article}
                      usepackage{chemfig}
                      makeatletter
                      CF@defsetangleincrement{defCF@angle@increment}
                      setangleincrement{45}% default value
                      defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                      ifx@empty#1@empty%
                      let#2CF@default@angle
                      else
                      if:expandafternoexpand@car#1@nil
                      if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                      pgfmathsetmacro#2{CF@previous@angle+expandafter@gobble@gobble#1}%
                      else
                      expandafterdefexpandafter#2expandafter{@gobble#1}%
                      fi
                      else
                      pgfmathsetmacro#2{#1*CF@angle@increment}%
                      fi% puis normalise l'angle entre 0 et 360
                      ifdimifdim#2pt<z@-fi#2pt>360pt pgfmathsetmacro #2{#2-360*floor(#2/360)}fi% si |#2|>360
                      fi
                      }
                      makeatother
                      begin{document}
                      45 degres increment: chemfig{-[9]-[-1]-[1]-[-1]}

                      setangleincrement{30}
                      30 degres increment: chemfig{-[1]-[-1]-[1]-[-1]}
                      end{document}


                      enter image description here







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered May 23 '15 at 11:13









                      unbonpetitunbonpetit

                      5,34511323




                      5,34511323























                          3














                          You can use setchemfig.



                          enter image description here



                          documentclass{article}
                          usepackage{chemfig}
                          begin{document}
                          setchemfig{angle increment=30}
                          chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
                          end{document}





                          share|improve this answer








                          New contributor




                          GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.

























                            3














                            You can use setchemfig.



                            enter image description here



                            documentclass{article}
                            usepackage{chemfig}
                            begin{document}
                            setchemfig{angle increment=30}
                            chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
                            end{document}





                            share|improve this answer








                            New contributor




                            GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.























                              3












                              3








                              3







                              You can use setchemfig.



                              enter image description here



                              documentclass{article}
                              usepackage{chemfig}
                              begin{document}
                              setchemfig{angle increment=30}
                              chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
                              end{document}





                              share|improve this answer








                              New contributor




                              GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.










                              You can use setchemfig.



                              enter image description here



                              documentclass{article}
                              usepackage{chemfig}
                              begin{document}
                              setchemfig{angle increment=30}
                              chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
                              end{document}






                              share|improve this answer








                              New contributor




                              GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.









                              share|improve this answer



                              share|improve this answer






                              New contributor




                              GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.









                              answered 10 hours ago









                              GRSousaJrGRSousaJr

                              412




                              412




                              New contributor




                              GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.





                              New contributor





                              GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.






                              GRSousaJr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.























                                  1














                                  Depending on the use case I'd use submols:



                                  documentclass{standalone}
                                  usepackage{chemfig}
                                  definesubmol{r}{-[::-60]}
                                  definesubmol{l}{-[::60]}
                                  begin{document}
                                  chemfig{[:30]-!r!l!r!l}
                                  end{document}





                                  share|improve this answer




























                                    1














                                    Depending on the use case I'd use submols:



                                    documentclass{standalone}
                                    usepackage{chemfig}
                                    definesubmol{r}{-[::-60]}
                                    definesubmol{l}{-[::60]}
                                    begin{document}
                                    chemfig{[:30]-!r!l!r!l}
                                    end{document}





                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      Depending on the use case I'd use submols:



                                      documentclass{standalone}
                                      usepackage{chemfig}
                                      definesubmol{r}{-[::-60]}
                                      definesubmol{l}{-[::60]}
                                      begin{document}
                                      chemfig{[:30]-!r!l!r!l}
                                      end{document}





                                      share|improve this answer













                                      Depending on the use case I'd use submols:



                                      documentclass{standalone}
                                      usepackage{chemfig}
                                      definesubmol{r}{-[::-60]}
                                      definesubmol{l}{-[::60]}
                                      begin{document}
                                      chemfig{[:30]-!r!l!r!l}
                                      end{document}






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 22 '15 at 13:00









                                      clemensclemens

                                      51.7k5131283




                                      51.7k5131283























                                          0














                                          Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-defining the code that processes the bond angle specification.
                                          (PS I'm rather new at doing this sort of thing, so improvement suggestions are welcome!)



                                          Somewhat arbitrarily, I'll choose letters a through l (lowercase ell) to represent the angles 0 through 330 degrees. Then, we just need to add some code to the bottom of the macro where the processing of the integer specifications takes place to process the letters instead of numbers:



                                          defCF@set@bondangle#1#2{
                                          ifx@empty#1@empty%
                                          let#2CF@default@angle
                                          else
                                          if
                                          ...% In the code I've removed, it reads the explicit angle specification
                                          else % Here is the new code
                                          ifnum0<0#1relax% First check if the input is an integer or a letter
                                          ifnum#1>7% If an integer, process as before. This code is unchanged
                                          pgfmathparse{#1-floor(#1/8)*8}
                                          ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                          edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                          else
                                          edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                          fi
                                          else% Otherwise, process the letter into an integer and assign the proper angle
                                          edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                          fi%
                                          fi
                                          fi
                                          }


                                          Note that only letters a through l are supported, and this can probably break in a number of unforeseen ways, including (I think) negative integer inputs (but those didn't work in the original implementation anyways). The line to check whether the input is an integer or letter is from here: How to check if the value of a parameter is a number? (see egreg's answer), and the code to check the case containing a letter was suggested by David Carlisle.



                                          MWE:



                                          documentclass{standalone}
                                          usepackage{chemfig}
                                          makeatletter
                                          defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                                          ifx@empty#1@empty%
                                          let#2CF@default@angle
                                          else
                                          if:expandafternoexpand@car#1@nil
                                          if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                                          pgfmathparse{CF@previous@angle+expandafter@gobble@gobble#1}%
                                          let#2pgfmathresult
                                          else
                                          expandafterdefexpandafter#2expandafter{@gobble#1}%
                                          fi% puis normalise l'angle entre 0 et 360
                                          ifdimifdim#2pt<z@-fi#2pt>360pt % si |#2|>360
                                          pgfmathparse{#2-360*floor(#2/360)}%
                                          ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+360}fi
                                          let#2pgfmathresult
                                          else
                                          ifdim#2pt<z@
                                          pgfmathparse{#2+360}%
                                          let#2pgfmathresult
                                          fi
                                          fi
                                          else
                                          ifnum0<0#1relax%
                                          ifnum#1>7
                                          pgfmathparse{#1-floor(#1/8)*8}%
                                          ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                          edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                          else
                                          edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                          fi
                                          else
                                          edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                          fi%
                                          fi
                                          fi
                                          }
                                          makeatother

                                          begin{document}
                                          chemfig{-[:30]-[l]-[b]-[:330]}
                                          end{document}


                                          enter image description here






                                          share|improve this answer






























                                            0














                                            Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-defining the code that processes the bond angle specification.
                                            (PS I'm rather new at doing this sort of thing, so improvement suggestions are welcome!)



                                            Somewhat arbitrarily, I'll choose letters a through l (lowercase ell) to represent the angles 0 through 330 degrees. Then, we just need to add some code to the bottom of the macro where the processing of the integer specifications takes place to process the letters instead of numbers:



                                            defCF@set@bondangle#1#2{
                                            ifx@empty#1@empty%
                                            let#2CF@default@angle
                                            else
                                            if
                                            ...% In the code I've removed, it reads the explicit angle specification
                                            else % Here is the new code
                                            ifnum0<0#1relax% First check if the input is an integer or a letter
                                            ifnum#1>7% If an integer, process as before. This code is unchanged
                                            pgfmathparse{#1-floor(#1/8)*8}
                                            ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                            edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                            else
                                            edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                            fi
                                            else% Otherwise, process the letter into an integer and assign the proper angle
                                            edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                            fi%
                                            fi
                                            fi
                                            }


                                            Note that only letters a through l are supported, and this can probably break in a number of unforeseen ways, including (I think) negative integer inputs (but those didn't work in the original implementation anyways). The line to check whether the input is an integer or letter is from here: How to check if the value of a parameter is a number? (see egreg's answer), and the code to check the case containing a letter was suggested by David Carlisle.



                                            MWE:



                                            documentclass{standalone}
                                            usepackage{chemfig}
                                            makeatletter
                                            defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                                            ifx@empty#1@empty%
                                            let#2CF@default@angle
                                            else
                                            if:expandafternoexpand@car#1@nil
                                            if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                                            pgfmathparse{CF@previous@angle+expandafter@gobble@gobble#1}%
                                            let#2pgfmathresult
                                            else
                                            expandafterdefexpandafter#2expandafter{@gobble#1}%
                                            fi% puis normalise l'angle entre 0 et 360
                                            ifdimifdim#2pt<z@-fi#2pt>360pt % si |#2|>360
                                            pgfmathparse{#2-360*floor(#2/360)}%
                                            ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+360}fi
                                            let#2pgfmathresult
                                            else
                                            ifdim#2pt<z@
                                            pgfmathparse{#2+360}%
                                            let#2pgfmathresult
                                            fi
                                            fi
                                            else
                                            ifnum0<0#1relax%
                                            ifnum#1>7
                                            pgfmathparse{#1-floor(#1/8)*8}%
                                            ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                            edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                            else
                                            edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                            fi
                                            else
                                            edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                            fi%
                                            fi
                                            fi
                                            }
                                            makeatother

                                            begin{document}
                                            chemfig{-[:30]-[l]-[b]-[:330]}
                                            end{document}


                                            enter image description here






                                            share|improve this answer




























                                              0












                                              0








                                              0







                                              Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-defining the code that processes the bond angle specification.
                                              (PS I'm rather new at doing this sort of thing, so improvement suggestions are welcome!)



                                              Somewhat arbitrarily, I'll choose letters a through l (lowercase ell) to represent the angles 0 through 330 degrees. Then, we just need to add some code to the bottom of the macro where the processing of the integer specifications takes place to process the letters instead of numbers:



                                              defCF@set@bondangle#1#2{
                                              ifx@empty#1@empty%
                                              let#2CF@default@angle
                                              else
                                              if
                                              ...% In the code I've removed, it reads the explicit angle specification
                                              else % Here is the new code
                                              ifnum0<0#1relax% First check if the input is an integer or a letter
                                              ifnum#1>7% If an integer, process as before. This code is unchanged
                                              pgfmathparse{#1-floor(#1/8)*8}
                                              ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                              edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                              else
                                              edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                              fi
                                              else% Otherwise, process the letter into an integer and assign the proper angle
                                              edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                              fi%
                                              fi
                                              fi
                                              }


                                              Note that only letters a through l are supported, and this can probably break in a number of unforeseen ways, including (I think) negative integer inputs (but those didn't work in the original implementation anyways). The line to check whether the input is an integer or letter is from here: How to check if the value of a parameter is a number? (see egreg's answer), and the code to check the case containing a letter was suggested by David Carlisle.



                                              MWE:



                                              documentclass{standalone}
                                              usepackage{chemfig}
                                              makeatletter
                                              defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                                              ifx@empty#1@empty%
                                              let#2CF@default@angle
                                              else
                                              if:expandafternoexpand@car#1@nil
                                              if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                                              pgfmathparse{CF@previous@angle+expandafter@gobble@gobble#1}%
                                              let#2pgfmathresult
                                              else
                                              expandafterdefexpandafter#2expandafter{@gobble#1}%
                                              fi% puis normalise l'angle entre 0 et 360
                                              ifdimifdim#2pt<z@-fi#2pt>360pt % si |#2|>360
                                              pgfmathparse{#2-360*floor(#2/360)}%
                                              ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+360}fi
                                              let#2pgfmathresult
                                              else
                                              ifdim#2pt<z@
                                              pgfmathparse{#2+360}%
                                              let#2pgfmathresult
                                              fi
                                              fi
                                              else
                                              ifnum0<0#1relax%
                                              ifnum#1>7
                                              pgfmathparse{#1-floor(#1/8)*8}%
                                              ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                              edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                              else
                                              edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                              fi
                                              else
                                              edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                              fi%
                                              fi
                                              fi
                                              }
                                              makeatother

                                              begin{document}
                                              chemfig{-[:30]-[l]-[b]-[:330]}
                                              end{document}


                                              enter image description here






                                              share|improve this answer















                                              Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-defining the code that processes the bond angle specification.
                                              (PS I'm rather new at doing this sort of thing, so improvement suggestions are welcome!)



                                              Somewhat arbitrarily, I'll choose letters a through l (lowercase ell) to represent the angles 0 through 330 degrees. Then, we just need to add some code to the bottom of the macro where the processing of the integer specifications takes place to process the letters instead of numbers:



                                              defCF@set@bondangle#1#2{
                                              ifx@empty#1@empty%
                                              let#2CF@default@angle
                                              else
                                              if
                                              ...% In the code I've removed, it reads the explicit angle specification
                                              else % Here is the new code
                                              ifnum0<0#1relax% First check if the input is an integer or a letter
                                              ifnum#1>7% If an integer, process as before. This code is unchanged
                                              pgfmathparse{#1-floor(#1/8)*8}
                                              ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                              edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                              else
                                              edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                              fi
                                              else% Otherwise, process the letter into an integer and assign the proper angle
                                              edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                              fi%
                                              fi
                                              fi
                                              }


                                              Note that only letters a through l are supported, and this can probably break in a number of unforeseen ways, including (I think) negative integer inputs (but those didn't work in the original implementation anyways). The line to check whether the input is an integer or letter is from here: How to check if the value of a parameter is a number? (see egreg's answer), and the code to check the case containing a letter was suggested by David Carlisle.



                                              MWE:



                                              documentclass{standalone}
                                              usepackage{chemfig}
                                              makeatletter
                                              defCF@set@bondangle#1#2{% le code de la direction est contenu dans #1, en sortie, #2 contient l'angle
                                              ifx@empty#1@empty%
                                              let#2CF@default@angle
                                              else
                                              if:expandafternoexpand@car#1@nil
                                              if:expandafterexpandafterexpandafternoexpandexpandafter@car@gobble#1@nil
                                              pgfmathparse{CF@previous@angle+expandafter@gobble@gobble#1}%
                                              let#2pgfmathresult
                                              else
                                              expandafterdefexpandafter#2expandafter{@gobble#1}%
                                              fi% puis normalise l'angle entre 0 et 360
                                              ifdimifdim#2pt<z@-fi#2pt>360pt % si |#2|>360
                                              pgfmathparse{#2-360*floor(#2/360)}%
                                              ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+360}fi
                                              let#2pgfmathresult
                                              else
                                              ifdim#2pt<z@
                                              pgfmathparse{#2+360}%
                                              let#2pgfmathresult
                                              fi
                                              fi
                                              else
                                              ifnum0<0#1relax%
                                              ifnum#1>7
                                              pgfmathparse{#1-floor(#1/8)*8}%
                                              ifdimpgfmathresult pt<z@pgfmathparse{pgfmathresult+8}fi
                                              edef#2{ifcaseexpandafterCF@int@partpgfmathresult@nil0or45or90or135or180or225or270or315else-1fi}
                                              else
                                              edef#2{ifcase#1 0or45or90or135or180or225or270or315else-1fi}%
                                              fi
                                              else
                                              edef#2{ifcasenumexpr`#1 - `arelax 0or30or60or90or120or150or180or210or240or270or300or330else-1fi}%
                                              fi%
                                              fi
                                              fi
                                              }
                                              makeatother

                                              begin{document}
                                              chemfig{-[:30]-[l]-[b]-[:330]}
                                              end{document}


                                              enter image description here







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Apr 13 '17 at 12:35









                                              Community

                                              1




                                              1










                                              answered May 22 '15 at 11:38









                                              darthbithdarthbith

                                              5,49332049




                                              5,49332049






























                                                  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%2f246368%2fis-there-a-shortcut-to-draw-30-degree-bond-angle-increments-in-chemfig%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

                                                  Contact image not getting when fetch all contact list from iPhone by CNContact

                                                  count number of partitions of a set with n elements into k subsets

                                                  A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks