+}
+
+# Returns a tag name from a tag link
+sub tagname ($) {
+ my $tag=shift;
+ if (defined $config{tagbase}) {
+ $tag =~ s!^/\Q$config{tagbase}\E/!!;
+ } else {
+ $tag =~ s!^\.?/!!;
+ }
+ return pagetitle($tag, 1);
+}
+
+sub htmllink_tag ($$$;@) {
+ my $page=shift;
+ my $destpage=shift;
+ my $tag=shift;
+ my %opts=@_;
+
+ return htmllink($page, $destpage, taglink($tag), %opts);
+}
+
+sub gentag ($) {
+ my $tag=shift;
+
+ if ($config{tag_autocreate} ||
+ ($config{tagbase} && ! defined $config{tag_autocreate})) {
+ my $tagpage=taglink($tag);
+ if ($tagpage=~/^\.\/(.*)/) {
+ $tagpage=$1;
+ }
+ else {
+ $tagpage=~s/^\///;
+ }
+
+ my $tagfile = newpagefile($tagpage, $config{default_pageext});
+
+ add_autofile($tagfile, "tag", sub {
+ my $message=sprintf(gettext("creating tag page %s"), $tagpage);
+ debug($message);