Is there a shortcut to draw 30 degree bond angle increments in ChemFig?
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
add a comment |
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
add a comment |
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
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
chemfig
asked May 22 '15 at 11:38
darthbithdarthbith
5,49332049
5,49332049
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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}
add a comment |
You can use setchemfig
.
documentclass{article}
usepackage{chemfig}
begin{document}
setchemfig{angle increment=30}
chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
end{document}
New contributor
add a comment |
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}
add a comment |
Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-def
ining 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}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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}
add a comment |
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}
add a comment |
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}
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}
answered May 23 '15 at 11:13
unbonpetitunbonpetit
5,34511323
5,34511323
add a comment |
add a comment |
You can use setchemfig
.
documentclass{article}
usepackage{chemfig}
begin{document}
setchemfig{angle increment=30}
chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
end{document}
New contributor
add a comment |
You can use setchemfig
.
documentclass{article}
usepackage{chemfig}
begin{document}
setchemfig{angle increment=30}
chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
end{document}
New contributor
add a comment |
You can use setchemfig
.
documentclass{article}
usepackage{chemfig}
begin{document}
setchemfig{angle increment=30}
chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
end{document}
New contributor
You can use setchemfig
.
documentclass{article}
usepackage{chemfig}
begin{document}
setchemfig{angle increment=30}
chemfig{-[1]-[-1]-[1]-[-1]-[1]-[-1]-[1]}
end{document}
New contributor
New contributor
answered 10 hours ago
GRSousaJrGRSousaJr
412
412
New contributor
New contributor
add a comment |
add a comment |
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}
add a comment |
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}
add a comment |
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}
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}
answered May 22 '15 at 13:00
clemensclemens
51.7k5131283
51.7k5131283
add a comment |
add a comment |
Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-def
ining 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}
add a comment |
Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-def
ining 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}
add a comment |
Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-def
ining 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}
Well, there is no built-in way to use such a shortcut. But, we can hack one together by re-def
ining 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}
edited Apr 13 '17 at 12:35
Community♦
1
1
answered May 22 '15 at 11:38
darthbithdarthbith
5,49332049
5,49332049
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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