2015年12月4日 星期五

寫一個 Script 產生 Reference 格式(網頁資料)

寫一個 Shell Script → refCreate.sh
#!/bin/bash
#
# latex reference create

if [ -z $1 ]; then
        echo ======== refCreate_latex.sh [ref.txt] ============
        exit
fi

DATE=`date +%Y-%m-%d`
FILE=$1
COUNT=`cat $FILE | wc -l`

for i in `seq 1 ${COUNT}`
do
RN=ref${i}
TITLE=`cat $FILE | cut -d '|' -f 1 | sed -n ${i}p`
URL=`cat $FILE | cut -d '|' -f 2 | sed -n ${i}p`

echo "
@misc{${RN},
        title={${TITLE}},
        howpublished={\url{${URL}}},
        note={Accessed:${DATE}}
}"
done

echo ============ Latex nocite create ===========
echo -n "\\nocite{"
for i in `seq 1 $COUNT`
do
        if [ $i != $COUNT ]; then
        echo -n "ref${i},"
        else
        echo -n "ref${i}}"
        fi
done
echo
echo

---
寫一個 ref.txt 整理需要放上的資料,格式為: Title|URL
(※注意中間使用管線 | 來分隔 Title 及 URL,並用 enter 換行分隔參考資料) 
例 --
Java Gossip: 實作 Runnable 介面|http://openhome.cc/Gossip/JavaGossip-V2/RunnableInterface.htm
Generate a random point within a circle (uniformly)|http://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly
Animation_2D Graphics GUI_Java|http://www.java2s.com/Code/Java/2D-Graphics-GUI/Animation.htm
Animation|http://zetcode.com/tutorials/javagamestutorial/animation/
(swing)輸入帳密視窗|http://blog.xuite.net/ray00000test/blog/21526707-(swing)%E8%BC%B8%E5%85%A5%E5%B8%B3%E5%AF%86%E8%A6%96%E7%AA%97
給初學 Android 的你|http://kenji-chao.blogspot.tw/2013/02/android.html
---
用法:
chmod +x refCreate.sh
./refCreate.sh ref.txt
---
輸出:
@misc{ref1,
        title={Java Gossip: 實作 Runnable 介面},
        howpublished={\url{http://openhome.cc/Gossip/JavaGossip-V2/RunnableInterface.htm}},
        note={Accessed:2015-12-04}
}

@misc{ref2,
        title={Generate a random point within a circle (uniformly)},
        howpublished={\url{http://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly}},
        note={Accessed:2015-12-04}
}

@misc{ref3,
        title={Animation_2D Graphics GUI_Java},
        howpublished={\url{http://www.java2s.com/Code/Java/2D-Graphics-GUI/Animation.htm}},
        note={Accessed:2015-12-04}
}

@misc{ref4,
        title={Animation},
        howpublished={\url{http://zetcode.com/tutorials/javagamestutorial/animation/}},
        note={Accessed:2015-12-04}
}

@misc{ref5,
        title={(swing)輸入帳密視窗},
        howpublished={\url{http://blog.xuite.net/ray00000test/blog/21526707-(swing)%E8%BC%B8%E5%85%A5%E5%B8%B3%E5%AF%86%E8%A6%96%E7%AA%97}},
        note={Accessed:2015-12-04}
}

@misc{ref6,
        title={給初學 Android 的你},
        howpublished={\url{http://kenji-chao.blogspot.tw/2013/02/android.html}},
        note={Accessed:2015-12-04}
}
============ Latex nocite create ===========
\nocite{ref1,ref2,ref3,ref4,ref5,ref6}
---

於所要編寫的 .tex 檔內,加入參考資料語法:
\begin{filecontents}{\jobname.bib}
@misc{ref1,
        title={Java Gossip: 實作 Runnable 介面},
        howpublished={\url{http://openhome.cc/Gossip/JavaGossip-V2/RunnableInterface.htm}},
        note={Accessed:2015-12-03}
}

@misc{ref2,
        title={Generate a random point within a circle (uniformly)},
        howpublished={\url{http://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly}},
        note={Accessed:2015-12-03}
}

@misc{ref3,
        title={Animation\_2D Graphics GUI\_Java},
        howpublished={\url{http://www.java2s.com/Code/Java/2D-Graphics-GUI/Animation.htm}},
        note={Accessed:2015-12-03}
}

@misc{ref4,
        title={Animation},
        howpublished={\url{http://zetcode.com/tutorials/javagamestutorial/animation/}},
        note={Accessed:2015-12-03}
}

@misc{ref5,
        title={(swing)輸入帳密視窗},
        howpublished={\url{http://blog.xuite.net/ray00000test/blog/21526707-(swing)%E8%BC%B8%E5%85%A5%E5%B8%B3%E5%AF%86%E8%A6%96%E7%AA%97}},
        note={Accessed:2015-12-03}
}

@misc{ref6,
        title={給初學 Android 的你},
        howpublished={\url{http://kenji-chao.blogspot.tw/2013/02/android.html}},
        note={Accessed:2015-12-03}
}
\end{filecontents}
---
並加到所要顯示的頁面,以 \nocite 來加入:
\section{Reference}
\frame{\frametitle{Outline}\tableofcontents[currentsection]}
\begin{frame}[allowframebreaks]
        \frametitle{Reference}
        \nocite{ref1,ref2,ref3,ref4,ref5,ref6}
        \tiny{\bibliographystyle{abbrv} }       % 文獻標號
        \bibliography{\jobname}                 % 文獻來源
\end{frame}