Spacing after a tikz figureSymbol for external linksTikZ: Cropping the Bounding Boxhow to set the canvas and font size in TikZ?How to define the default vertical distance between nodes?How to fill a line one-sided using TikZ?Line up nested tikz enviroments or how to get rid of themTikZ: Place different elements of a same path on various layerstikz - gradient along a bendy pathSpacing after figure without captionThe TikZ pipeline: A path's 'draw' option has no effect on a 'behind path' nodeTikZ and FIFA WorldCup 2018: Flags of Nations
Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?
Is it error of law to judge on less relevant case law when there is much more relevant one?
Copying an existing HTML page and use it, is that against any copyright law?
Anti-cheating: should there be a limit to a number of toilet breaks per game per player?
Desktop app status bar: Notification vs error message
Does Dispel Magic destroy Artificer Turrets?
Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?
How did the Axis intend to hold the Caucasus?
Is it safe if the neutral lead is exposed and disconnected?
What steps would an amateur scientist have to take in order to get a scientific breakthrough published?
How could Nomadic scholars effectively memorize libraries worth of information
How long until two planets become one?
What did G-d do before Creation?
Compound Word Neologism
Why isn't there any 9.5 digit multimeter or higher?
Why does Canada require mandatory bilingualism in a lot of federal government posts?
How do I use JSON.generator to generate an unnamed array?
Is there an antonym(a complementary antonym) for "spicy" or "hot" regarding food (I do NOT mean "seasoned" but "hot")?
Exploiting the delay when a festival ticket is scanned
How can Paypal know my card is being used in another account?
How many oliphaunts died in all of the Lord of the Rings battles?
What is more environmentally friendly? An A320 or a car?
If Trump gets impeached, how long would Pence be president?
What are the closest international airports in different countries?
Spacing after a tikz figure
Symbol for external linksTikZ: Cropping the Bounding Boxhow to set the canvas and font size in TikZ?How to define the default vertical distance between nodes?How to fill a line one-sided using TikZ?Line up nested tikz enviroments or how to get rid of themTikZ: Place different elements of a same path on various layerstikz - gradient along a bendy pathSpacing after figure without captionThe TikZ pipeline: A path's 'draw' option has no effect on a 'behind path' nodeTikZ and FIFA WorldCup 2018: Flags of Nations
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?
documentclassarticle
usepackagetikz,hyperref
newcommandExternalLink%
tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
letorighrefhref
renewcommandhref[2]orighref#1#2$,$ExternalLink
begindocument
noindent
Some text hrefhttp://google.comlink some more text.\
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
enddocument
tikz-pgf spacing
add a comment |
I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?
documentclassarticle
usepackagetikz,hyperref
newcommandExternalLink%
tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
letorighrefhref
renewcommandhref[2]orighref#1#2$,$ExternalLink
begindocument
noindent
Some text hrefhttp://google.comlink some more text.\
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
enddocument
tikz-pgf spacing
add a comment |
I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?
documentclassarticle
usepackagetikz,hyperref
newcommandExternalLink%
tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
letorighrefhref
renewcommandhref[2]orighref#1#2$,$ExternalLink
begindocument
noindent
Some text hrefhttp://google.comlink some more text.\
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
enddocument
tikz-pgf spacing
I'm trying to add an external link symbol (from https://tex.stackexchange.com/a/294990/163482) to href but for some reason the spacing after the symbol is wrong when I redefine the href command. What would the right way to do it (and what would be the right amount of space)?
documentclassarticle
usepackagetikz,hyperref
newcommandExternalLink%
tikz[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]%
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
letorighrefhref
renewcommandhref[2]orighref#1#2$,$ExternalLink
begindocument
noindent
Some text hrefhttp://google.comlink some more text.\
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
enddocument
tikz-pgf spacing
tikz-pgf spacing
asked 9 hours ago
Nicolas RougierNicolas Rougier
1505 bronze badges
1505 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When you write:
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
the space after ExternalLink
is ignored by TeX, because ExternalLink
is a control sequence whose name ends with a letter. On the contrary, with:
Some text hrefhttp://google.comlink some more text.
there is a space token after link
, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:
Some text hrefhttp://google.comlinksome more text.
or use ignorespaces
in your redefinition of href
so as to ignore spaces following in the input (ignorespaces
expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):
renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces
But actually, you don't want to use any of these suggestions. This is because in your ExternalLink
command, there is a most probably unwanted space:
newcommandExternalLink%
...
path[draw=black, ...] ... ;
% <------- here, remove the space
}
So, your ExternalLink
command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces
anymore.
Also note that you don't need to be in math mode in order to use ,
; it produces a thinspace
when used outside of math mode. So, you can do something like:
renewcommand*href[2]orighref#1#2,ExternalLink
Other suggestion: you may want to include the icon inside the clickable link:
renewcommand*href[2]orighref#1#2,ExternalLink
I used renewcommand*
because the arguments of href
most probably shouldn't contain par
tokens; this makes finding errors easier.
Note: there won't be a line break at the ,
, because this macro expands to thinspace
in non-math mode, which itself expands to a kern
, and there can be a break at a kern
only if it's immediately followed by glue—which isn't the case here, as ExternalLink
starts with a box: the TikZ picture.
Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href
(i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox
command doesn't need to be protect
ed, as the example shows):
documentclassarticle
usepackagetikz
usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links
newsaveboxExternalLinkIcon
beginlrboxExternalLinkIcon
begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
endtikzpicture% <--- important!
endlrbox
letorighrefhref
renewcommand*href[2]%
orighref#1#2,useboxExternalLinkIcon%
begindocument
noindent
Some text hrefhttp://example.comlink some more text. Spacing is also fine
before a hrefhttp://example.comcomma, as you can see. Periods are fine
too, of course---we don't have to do anything special.
beginfigure[htbp]
centering
This is the figure contents.
captionA caption containing a hrefhttp://example.comhyperlink
endfigure
enddocument
Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...
– Nicolas Rougier
7 hours ago
1
This is probably due to the fact that a caption is subject toprotected@write
for the list of figures or list of tables, andprotected@write
tries to expand everything that is neitherprotected
nor preceded byprotect
. You can usenewrobustcmd*
from theetoolbox
package, that is slightly better.
– frougon
7 hours ago
There was a spurious space at the end of yourExternalLink
command. This changes everything! Please reread my answer...
– frougon
5 hours ago
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%2f501981%2fspacing-after-a-tikz-figure%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
When you write:
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
the space after ExternalLink
is ignored by TeX, because ExternalLink
is a control sequence whose name ends with a letter. On the contrary, with:
Some text hrefhttp://google.comlink some more text.
there is a space token after link
, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:
Some text hrefhttp://google.comlinksome more text.
or use ignorespaces
in your redefinition of href
so as to ignore spaces following in the input (ignorespaces
expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):
renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces
But actually, you don't want to use any of these suggestions. This is because in your ExternalLink
command, there is a most probably unwanted space:
newcommandExternalLink%
...
path[draw=black, ...] ... ;
% <------- here, remove the space
}
So, your ExternalLink
command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces
anymore.
Also note that you don't need to be in math mode in order to use ,
; it produces a thinspace
when used outside of math mode. So, you can do something like:
renewcommand*href[2]orighref#1#2,ExternalLink
Other suggestion: you may want to include the icon inside the clickable link:
renewcommand*href[2]orighref#1#2,ExternalLink
I used renewcommand*
because the arguments of href
most probably shouldn't contain par
tokens; this makes finding errors easier.
Note: there won't be a line break at the ,
, because this macro expands to thinspace
in non-math mode, which itself expands to a kern
, and there can be a break at a kern
only if it's immediately followed by glue—which isn't the case here, as ExternalLink
starts with a box: the TikZ picture.
Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href
(i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox
command doesn't need to be protect
ed, as the example shows):
documentclassarticle
usepackagetikz
usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links
newsaveboxExternalLinkIcon
beginlrboxExternalLinkIcon
begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
endtikzpicture% <--- important!
endlrbox
letorighrefhref
renewcommand*href[2]%
orighref#1#2,useboxExternalLinkIcon%
begindocument
noindent
Some text hrefhttp://example.comlink some more text. Spacing is also fine
before a hrefhttp://example.comcomma, as you can see. Periods are fine
too, of course---we don't have to do anything special.
beginfigure[htbp]
centering
This is the figure contents.
captionA caption containing a hrefhttp://example.comhyperlink
endfigure
enddocument
Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...
– Nicolas Rougier
7 hours ago
1
This is probably due to the fact that a caption is subject toprotected@write
for the list of figures or list of tables, andprotected@write
tries to expand everything that is neitherprotected
nor preceded byprotect
. You can usenewrobustcmd*
from theetoolbox
package, that is slightly better.
– frougon
7 hours ago
There was a spurious space at the end of yourExternalLink
command. This changes everything! Please reread my answer...
– frougon
5 hours ago
add a comment |
When you write:
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
the space after ExternalLink
is ignored by TeX, because ExternalLink
is a control sequence whose name ends with a letter. On the contrary, with:
Some text hrefhttp://google.comlink some more text.
there is a space token after link
, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:
Some text hrefhttp://google.comlinksome more text.
or use ignorespaces
in your redefinition of href
so as to ignore spaces following in the input (ignorespaces
expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):
renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces
But actually, you don't want to use any of these suggestions. This is because in your ExternalLink
command, there is a most probably unwanted space:
newcommandExternalLink%
...
path[draw=black, ...] ... ;
% <------- here, remove the space
}
So, your ExternalLink
command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces
anymore.
Also note that you don't need to be in math mode in order to use ,
; it produces a thinspace
when used outside of math mode. So, you can do something like:
renewcommand*href[2]orighref#1#2,ExternalLink
Other suggestion: you may want to include the icon inside the clickable link:
renewcommand*href[2]orighref#1#2,ExternalLink
I used renewcommand*
because the arguments of href
most probably shouldn't contain par
tokens; this makes finding errors easier.
Note: there won't be a line break at the ,
, because this macro expands to thinspace
in non-math mode, which itself expands to a kern
, and there can be a break at a kern
only if it's immediately followed by glue—which isn't the case here, as ExternalLink
starts with a box: the TikZ picture.
Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href
(i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox
command doesn't need to be protect
ed, as the example shows):
documentclassarticle
usepackagetikz
usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links
newsaveboxExternalLinkIcon
beginlrboxExternalLinkIcon
begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
endtikzpicture% <--- important!
endlrbox
letorighrefhref
renewcommand*href[2]%
orighref#1#2,useboxExternalLinkIcon%
begindocument
noindent
Some text hrefhttp://example.comlink some more text. Spacing is also fine
before a hrefhttp://example.comcomma, as you can see. Periods are fine
too, of course---we don't have to do anything special.
beginfigure[htbp]
centering
This is the figure contents.
captionA caption containing a hrefhttp://example.comhyperlink
endfigure
enddocument
Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...
– Nicolas Rougier
7 hours ago
1
This is probably due to the fact that a caption is subject toprotected@write
for the list of figures or list of tables, andprotected@write
tries to expand everything that is neitherprotected
nor preceded byprotect
. You can usenewrobustcmd*
from theetoolbox
package, that is slightly better.
– frougon
7 hours ago
There was a spurious space at the end of yourExternalLink
command. This changes everything! Please reread my answer...
– frougon
5 hours ago
add a comment |
When you write:
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
the space after ExternalLink
is ignored by TeX, because ExternalLink
is a control sequence whose name ends with a letter. On the contrary, with:
Some text hrefhttp://google.comlink some more text.
there is a space token after link
, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:
Some text hrefhttp://google.comlinksome more text.
or use ignorespaces
in your redefinition of href
so as to ignore spaces following in the input (ignorespaces
expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):
renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces
But actually, you don't want to use any of these suggestions. This is because in your ExternalLink
command, there is a most probably unwanted space:
newcommandExternalLink%
...
path[draw=black, ...] ... ;
% <------- here, remove the space
}
So, your ExternalLink
command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces
anymore.
Also note that you don't need to be in math mode in order to use ,
; it produces a thinspace
when used outside of math mode. So, you can do something like:
renewcommand*href[2]orighref#1#2,ExternalLink
Other suggestion: you may want to include the icon inside the clickable link:
renewcommand*href[2]orighref#1#2,ExternalLink
I used renewcommand*
because the arguments of href
most probably shouldn't contain par
tokens; this makes finding errors easier.
Note: there won't be a line break at the ,
, because this macro expands to thinspace
in non-math mode, which itself expands to a kern
, and there can be a break at a kern
only if it's immediately followed by glue—which isn't the case here, as ExternalLink
starts with a box: the TikZ picture.
Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href
(i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox
command doesn't need to be protect
ed, as the example shows):
documentclassarticle
usepackagetikz
usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links
newsaveboxExternalLinkIcon
beginlrboxExternalLinkIcon
begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
endtikzpicture% <--- important!
endlrbox
letorighrefhref
renewcommand*href[2]%
orighref#1#2,useboxExternalLinkIcon%
begindocument
noindent
Some text hrefhttp://example.comlink some more text. Spacing is also fine
before a hrefhttp://example.comcomma, as you can see. Periods are fine
too, of course---we don't have to do anything special.
beginfigure[htbp]
centering
This is the figure contents.
captionA caption containing a hrefhttp://example.comhyperlink
endfigure
enddocument
When you write:
Some text orighrefhttp://google.comlink$,$ExternalLink some more text.
the space after ExternalLink
is ignored by TeX, because ExternalLink
is a control sequence whose name ends with a letter. On the contrary, with:
Some text hrefhttp://google.comlink some more text.
there is a space token after link
, and it is not ignored. It contributes an interword space to the horizontal list under construction. That is why you see a larger space in the first case of your example (second case here). In order to get rid of this additional space, you can either write:
Some text hrefhttp://google.comlinksome more text.
or use ignorespaces
in your redefinition of href
so as to ignore spaces following in the input (ignorespaces
expands tokens from the input stream until it finds an unexpandable token that is not a 〈space token〉, according to the TeX grammar):
renewcommand*href[2]orighref#1#2$,$ExternalLinkignorespaces
But actually, you don't want to use any of these suggestions. This is because in your ExternalLink
command, there is a most probably unwanted space:
newcommandExternalLink%
...
path[draw=black, ...] ... ;
% <------- here, remove the space
}
So, your ExternalLink
command unconditionally adds this space after the icon. I believe this is unwanted when the hyperlink is followed by a comma or a period, for instance. Therefore I'd remove this space; then you don't need ignorespaces
anymore.
Also note that you don't need to be in math mode in order to use ,
; it produces a thinspace
when used outside of math mode. So, you can do something like:
renewcommand*href[2]orighref#1#2,ExternalLink
Other suggestion: you may want to include the icon inside the clickable link:
renewcommand*href[2]orighref#1#2,ExternalLink
I used renewcommand*
because the arguments of href
most probably shouldn't contain par
tokens; this makes finding errors easier.
Note: there won't be a line break at the ,
, because this macro expands to thinspace
in non-math mode, which itself expands to a kern
, and there can be a break at a kern
only if it's immediately followed by glue—which isn't the case here, as ExternalLink
starts with a box: the TikZ picture.
Final remark: your links are going to make TeX work hard on the TikZ picture every time you use this redefined href
(i.e., for every hyperlink). Since the icon is always the same, there is a way to save on compilation time: save the picture once inside a box, then use the box whenever you need it. That is very cheap on computing resources. All in all, here is my suggestion (I added a picture with a caption because of our discussion in the comments—the usebox
command doesn't need to be protect
ed, as the example shows):
documentclassarticle
usepackagetikz
usepackage[hidelinks]hyperref % 'hidelinks' removes the border around links
newsaveboxExternalLinkIcon
beginlrboxExternalLinkIcon
begintikzpicture[x=1.2ex, y=1.2ex, baseline=-0.5ex, scale=0.75]
beginscope[x=1ex, y=1ex]
clip (-0.1,-0.1)
--++ (-0, 1.2)
--++ (0.6, 0)
--++ (0, -0.6)
--++ (0.6, 0)
--++ (0, -1);
path[draw=black, line width = 0.5,
rounded corners=0.5] (0,0) rectangle (1,1);
endscope
path[draw=black, line width = 0.5] (0.5, 0.5) -- (1, 1);
path[draw=black, line width = 0.5] (0.6, 1) -- (1, 1) -- (1, 0.6);
endtikzpicture% <--- important!
endlrbox
letorighrefhref
renewcommand*href[2]%
orighref#1#2,useboxExternalLinkIcon%
begindocument
noindent
Some text hrefhttp://example.comlink some more text. Spacing is also fine
before a hrefhttp://example.comcomma, as you can see. Periods are fine
too, of course---we don't have to do anything special.
beginfigure[htbp]
centering
This is the figure contents.
captionA caption containing a hrefhttp://example.comhyperlink
endfigure
enddocument
edited 5 hours ago
answered 9 hours ago
frougonfrougon
6,0251 gold badge10 silver badges20 bronze badges
6,0251 gold badge10 silver badges20 bronze badges
Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...
– Nicolas Rougier
7 hours ago
1
This is probably due to the fact that a caption is subject toprotected@write
for the list of figures or list of tables, andprotected@write
tries to expand everything that is neitherprotected
nor preceded byprotect
. You can usenewrobustcmd*
from theetoolbox
package, that is slightly better.
– frougon
7 hours ago
There was a spurious space at the end of yourExternalLink
command. This changes everything! Please reread my answer...
– frougon
5 hours ago
add a comment |
Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...
– Nicolas Rougier
7 hours ago
1
This is probably due to the fact that a caption is subject toprotected@write
for the list of figures or list of tables, andprotected@write
tries to expand everything that is neitherprotected
nor preceded byprotect
. You can usenewrobustcmd*
from theetoolbox
package, that is slightly better.
– frougon
7 hours ago
There was a spurious space at the end of yourExternalLink
command. This changes everything! Please reread my answer...
– frougon
5 hours ago
Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...
– Nicolas Rougier
7 hours ago
Thanks, works nicely but I just realized the tikz part was not working inside a caption. It needs a DeclareRobustCommandExternaLink...
– Nicolas Rougier
7 hours ago
1
1
This is probably due to the fact that a caption is subject to
protected@write
for the list of figures or list of tables, and protected@write
tries to expand everything that is neither protected
nor preceded by protect
. You can use newrobustcmd*
from the etoolbox
package, that is slightly better.– frougon
7 hours ago
This is probably due to the fact that a caption is subject to
protected@write
for the list of figures or list of tables, and protected@write
tries to expand everything that is neither protected
nor preceded by protect
. You can use newrobustcmd*
from the etoolbox
package, that is slightly better.– frougon
7 hours ago
There was a spurious space at the end of your
ExternalLink
command. This changes everything! Please reread my answer...– frougon
5 hours ago
There was a spurious space at the end of your
ExternalLink
command. This changes everything! Please reread my answer...– frougon
5 hours ago
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%2f501981%2fspacing-after-a-tikz-figure%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