0に立ち返ってのTex文書操作/書籍内外と連携する

  • hyperrefパッケージを使うので、冒頭に
\usepackage[dvipdfmx,setpagesize=false]{hyperref}
  • と書いておきます。
  • jsarticleとの競合があるらしいので、特にsetpagesize=falseという宣言を入れておくらしいです
  • 使ってみましょう
    • こちらを参考に書いてみました。
  • Rnwで書いて、Sweave()で
Sweave("useHyperref.Rnw",encoding="SJIS")
  • tex化して、それをタイプセットx2回して、リンクが完成
  • Rnwとtexとpdfとを以下につけます
  • まずはuseHyperref.Rnwファイル
\documentclass{jsarticle}

\usepackage{amsmath,amssymb}
\usepackage{bm}
%\usepackage{graphicx}
\usepackage{ascmac}
\usepackage[dvips]{graphicx}
\usepackage{graphicx}
\usepackage{bigdelim,multirow}
\usepackage{amsmath,amsthm,amssymb,cases}
\usepackage{ascmac}
\usepackage{eclbkbox}
\usepackage{wrapfig}
\usepackage{listings, jlisting}
\usepackage{color}
\usepackage{makeidx}
\usepackage{url}
\usepackage[dvipdfmx,setpagesize=false]{hyperref}
\SweaveOpts{eps=TRUE}
\begin{document}
\section{hyperrefを使おう}\label{myD1S1}
\subsection{インターネット上のサイトへのリンクを張る}\label{myD1S1SS1}
\href{http://www.clas.kitasato-u.ac.jp/~fujiwara/infoScienceB/TeX/ref/labelAndRef.html}{文書内リンクの張り方のサイト}\\

この文字列『文書内リンクの張り方のサイト』はハイライトされていて、クリッカブルでウェブサイトにリンクが張られています。\\

このようなurlの埋め込みをするには、次のように書きます。\\

\verb|\href{http://www.clas.kitasato-u.ac.jp/~fujiwara/infoScienceB/TeX/ref/labelAndRef.html}{文書内リンクの張り方のサイト}|\\ 

第一の{}の中にurlを、第二の{}の中にハイライトされる文字列を書きます。

\subsection{ページ稼ぎのサブセクション}\label{myD1S1SS2}
Rでプロットをさせて少しページ稼ぎをしてみます。
<<fig=TRUE>>=
data<-runif(100)
plot(sort(data))
@
\section{文書内でリンクを張る}\label{myD1S2}
\subsection{セクションにジャンプする}\label{myD1S2SS1}
ここから文書の最初のセクション\ref{myD1S1}に戻ります。\\
最初のセクションのところは\\
\\
\verb|\section{hyperrefを使おう}\label{myD1S1}|\\
\\
と言うように\verb|\label{}|という仕組みを使ってありました。\\
飛ぶ先はこのように\verb|\label{}|で指定します。飛ぶ元は\\
\\
\verb|書の最初のセクション\ref{myD1S1}に|\\
\\
というように\verb|\ref{}|と書いておきます。\\
後ろにあるセクション3にもジャンプしてみます:セクション\ref{myD1S3}へ。\\

なお、リンクを作るときには、texがtex文書を前から後ろへ読みながら、内部リンクを探しますので、1回目のタイプセット(pdfpLaTeXとか)は、相互関係を見つけられないので、リンクがうまく張れずに「?」が現れます。もう一度タイプセットを実行すると問題は解消します。\\
\subsection{ラベルのあるページにジャンプする}\label{myD1S2SS2}
前のサブセクションのあるページの先頭にジャンプする(\pageref{myD1S2SS1})。\\
セクションに飛ぶのと同様に、ラベルの張ってある行があるページ(の先頭)に戻るには\\
\\
\verb|\pageref{myD1S2SS1}|\\
\\
のように\verb|\pageref|を使います。ここでは、一つ前のサブセクション「セクションにジャンプする」のページを指定してあります。
セクション3があるのは\pageref{myD1S3}ページです。そこへリンクしました。\\

\subsection{文書内の任意の場所にジャンプする}\label{myD1S2SS3}
第3セクションには英文が書いてあって、その中に「宝」と「千両箱」が埋まっています。そこへジャンプしてみます。\\
\hyperlink{t1}{宝へのリンク}\\
\hyperlink{t2}{千両箱へのリンク}\\

<<fig=TRUE>>=
data<-rnorm(100)
plot(sort(data))
@

\section{次のセクション}\label{myD1S3}
Wikipedia 英語版のEgyptの記事からの抜粋です。この中に、日本語の「宝」や「千両箱」を埋め込んでおき、そこにジャンプできるようにしておきましょう。\\
\verb|\hypertarget{t1}{宝}|,\verb|\hypertarget{t2}{千両箱}|のように埋め込んであります。\\

Egypt is one of the most populous countries in Africa and the Middle East, and the 15th most populated in the world. The great majority of its over 84 million people[4] live near the banks of the Nile River, an area of about 40,000 square kilometers (15,000 sq mi), where the only arable land is found. The large regions of the Sahara Desert, which constitute most of Egypt's territory, are sparsely inhabited. About half of Egypt's residents \textcolor{green}{\hypertarget{t1}{}} live in urban areas, with most spread across the densely populated centres of greater Cairo, Alexandria and other major cities in the Nile Delta.\\
Egypt has one of the longest histories of any modern state, having been continuously inhabited since the 10th millennium BC.[10] Its monuments, such as the Giza pyramid complex and its Great Sphinx, were constructed by its ancient civilization, which was one of the most advanced of its time. Its ancient ruins, such as those of Memphis, Thebes, Karnak, and the Valley of the Kings outside Luxor, are a significant focus of archaeological study and popular interest. Egypt's rich cultural legacy, as well as the attraction of its Red Sea Riviera, have made tourism a vital part of the economy, employing about 12% of the country's workforce.\\
The economy of Egypt is one of the most diversified in the Middle East, with sectors such as tourism, agriculture, industry and services at almost equal production levels. Egypt is considered to be a middle power,[11] with significant cultural, political, and military influence in North Africa\textcolor{blue}{\hypertarget{t2}{千両箱}}, the Middle East and the Muslim world.\\


\end{document}
  • ついでtexファイルuseHyperref.tex
\documentclass{jsarticle}

\usepackage{amsmath,amssymb}
\usepackage{bm}
%\usepackage{graphicx}
\usepackage{ascmac}
\usepackage[dvips]{graphicx}
\usepackage{graphicx}
\usepackage{bigdelim,multirow}
\usepackage{amsmath,amsthm,amssymb,cases}
\usepackage{ascmac}
\usepackage{eclbkbox}
\usepackage{wrapfig}
\usepackage{listings, jlisting}
\usepackage{color}
\usepackage{makeidx}
\usepackage{url}
\usepackage[dvipdfmx,setpagesize=false]{hyperref}

\usepackage{Sweave}
\begin{document}
\section{hyperrefを使おう}\label{myD1S1}
\subsection{インターネット上のサイトへのリンクを張る}\label{myD1S1SS1}
\href{http://www.clas.kitasato-u.ac.jp/~fujiwara/infoScienceB/TeX/ref/labelAndRef.html}{文書内リンクの張り方のサイト}\\

この文字列『文書内リンクの張り方のサイト』はハイライトされていて、クリッカブルでウェブサイトにリンクが張られています。\\

このようなurlの埋め込みをするには、次のように書きます。\\

\verb|\href{http://www.clas.kitasato-u.ac.jp/~fujiwara/infoScienceB/TeX/ref/labelAndRef.html}{文書内リンクの張り方のサイト}|\\ 

第一の{}の中にurlを、第二の{}の中にハイライトされる文字列を書きます。

\subsection{ページ稼ぎのサブセクション}\label{myD1S1SS2}
Rでプロットをさせて少しページ稼ぎをしてみます。
\begin{Schunk}
\begin{Sinput}
> data<-runif(100)
> plot(sort(data))
\end{Sinput}
\end{Schunk}
\includegraphics{useHyperref-001}
\section{文書内でリンクを張る}\label{myD1S2}
\subsection{セクションにジャンプする}\label{myD1S2SS1}
ここから文書の最初のセクション\ref{myD1S1}に戻ります。\\
最初のセクションのところは\\
\\
\verb|\section{hyperrefを使おう}\label{myD1S1}|\\
\\
と言うように\verb|\label{}|という仕組みを使ってありました。\\
飛ぶ先はこのように\verb|\label{}|で指定します。飛ぶ元は\\
\\
\verb|書の最初のセクション\ref{myD1S1}に|\\
\\
というように\verb|\ref{}|と書いておきます。\\
後ろにあるセクション3にもジャンプしてみます:セクション\ref{myD1S3}へ。\\

なお、リンクを作るときには、texがtex文書を前から後ろへ読みながら、内部リンクを探しますので、1回目のタイプセット(pdfpLaTeXとか)は、相互関係を見つけられないので、リンクがうまく張れずに「?」が現れます。もう一度タイプセットを実行すると問題は解消します。\\
\subsection{ラベルのあるページにジャンプする}\label{myD1S2SS2}
前のサブセクションのあるページの先頭にジャンプする(\pageref{myD1S2SS1})。\\
セクションに飛ぶのと同様に、ラベルの張ってある行があるページ(の先頭)に戻るには\\
\\
\verb|\pageref{myD1S2SS1}|\\
\\
のように\verb|\pageref|を使います。ここでは、一つ前のサブセクション「セクションにジャンプする」のページを指定してあります。
セクション3があるのは\pageref{myD1S3}ページです。そこへリンクしました。\\

\subsection{文書内の任意の場所にジャンプする}\label{myD1S2SS3}
第3セクションには英文が書いてあって、その中に「宝」と「千両箱」が埋まっています。そこへジャンプしてみます。\\
\hyperlink{t1}{宝へのリンク}\\
\hyperlink{t2}{千両箱へのリンク}\\

\begin{Schunk}
\begin{Sinput}
> data<-rnorm(100)
> plot(sort(data))
\end{Sinput}
\end{Schunk}
\includegraphics{useHyperref-002}

\section{次のセクション}\label{myD1S3}
Wikipedia 英語版のEgyptの記事からの抜粋です。この中に、日本語の「宝」や「千両箱」を埋め込んでおき、そこにジャンプできるようにしておきましょう。\\
\verb|\hypertarget{t1}{宝}|,\verb|\hypertarget{t2}{千両箱}|のように埋め込んであります。\\

Egypt is one of the most populous countries in Africa and the Middle East, and the 15th most populated in the world. The great majority of its over 84 million people[4] live near the banks of the Nile River, an area of about 40,000 square kilometers (15,000 sq mi), where the only arable land is found. The large regions of the Sahara Desert, which constitute most of Egypt's territory, are sparsely inhabited. About half of Egypt's residents \textcolor{green}{\hypertarget{t1}{}} live in urban areas, with most spread across the densely populated centres of greater Cairo, Alexandria and other major cities in the Nile Delta.\\
Egypt has one of the longest histories of any modern state, having been continuously inhabited since the 10th millennium BC.[10] Its monuments, such as the Giza pyramid complex and its Great Sphinx, were constructed by its ancient civilization, which was one of the most advanced of its time. Its ancient ruins, such as those of Memphis, Thebes, Karnak, and the Valley of the Kings outside Luxor, are a significant focus of archaeological study and popular interest. Egypt's rich cultural legacy, as well as the attraction of its Red Sea Riviera, have made tourism a vital part of the economy, employing about 12% of the country's workforce.\\
The economy of Egypt is one of the most diversified in the Middle East, with sectors such as tourism, agriculture, industry and services at almost equal production levels. Egypt is considered to be a middle power,[11] with significant cultural, political, and military influence in North Africa\textcolor{blue}{\hypertarget{t2}{千両箱}}, the Middle East and the Muslim world.\\


\end{document}
  • できたpdfファイルがこちら
    • ファイル内リンクは、ブラウザ上でもワークしていますが、ネット上のサイトへのリンクはブラウザ上では飛ばないようになるようです
    • ダウンロードしてやると飛べます
    • 不正なリンクの埋め込みとかがないように、というウイルスソフトとかブラウザの仕様が効いているのかと思います
  • 個々のRnw,tex文書については上記でOK
  • 多数のtex文書を束ねて「書籍」にするときも、各tex文書の冒頭に\hyperrefを埋め込めば、書籍全体で飛べるだろう
  • やってみる
  • texファイル testHyperrefBook.texを次のように書いて、useRtest_bare.texとuseHyperref_bare.texをそれぞれのRnw経由のtexファイルの\begin{document}と\end{document}の間の部分だけにしたものとして保存しておけば、読み込みリンクのトップに飛べる
\documentclass{jsbook}
\author{
氏名
}

\title{記事間連絡のある本を作ってみる}

\usepackage{amsmath,amssymb}
\usepackage{bm}
%\usepackage{graphicx}
\usepackage{ascmac}
\usepackage[dvips]{graphicx}
\usepackage{graphicx}
\usepackage{bigdelim,multirow}
\usepackage{amsmath,amsthm,amssymb,cases}
\usepackage{ascmac}
\usepackage{url}
\usepackage{eclbkbox}
\usepackage{wrapfig}
\usepackage{listings, jlisting}
\usepackage[dvips,usenames]{color}
\usepackage{makeidx}
\usepackage[dvipdfmx,setpagesize=false]{hyperref}
\renewcommand{\baselinestretch}{1}
\setlength{\textheight}{33\baselineskip}


\makeindex


%\setlength{\topmargin}{0mm}

\usepackage{Sweave}
\begin{document}
\maketitle
\tableofcontents
\mainmatter
\chapter{Rの基礎}
\include{useHyperref_bare}
\include{useRtest_bare}
2文書間の関係を書きたい\\
iseRtest bare文書は
useHyperref bareに関係しています。その冒頭に飛びたいなら、こちら\ref{myD1S1}\\
その中の「宝」へ飛びたいなら
\hyperlink{t1}{宝へのリンク}\\

\end{document}