Cross Reference in Markdown Files and Web Pages

Oct. 10, 2023

HTML <div> element

Fundamental usage

The cross reference in the Jekyll-based website could be realised by adding HTML <div> tag and whose id property in the .md file [1].

Firstly, use <div id="xxx"></div> to create a “division” in the specified position [2], like:

1
2
3
4
5
**References**
<div id="ref-1"></div>
[1] [Markdown 添加文献引用 - 别再闹了 - 博客园](https://www.cnblogs.com/jiading/articles/12966059.html).
<div id="ref-2"></div>
[2] [HTML div tag - w3schools](https://www.w3schools.com/tags/tag_div.ASP).

We could use adding hyperlink for text to refer division with a certain id:

1
2
3
This is reference [[1]](#ref-1).

This is reference [[2]](#ref-2).

This is reference [1].

This is reference [2].

After deploying web page, it will direct to the referred division when we clicking the text content with hyperlink, and the website address of the division is like:

image-20231010165147365

however, this function is not available in the original .md file.

The cases of Multiple definition and missing definition of HTML <div> tag

Added on Oct. 31, 2023.

If we inserted multiple divisions with the same id properties, for example, we defined two or more division using <div id="ref"></div>, no error will occur. However, when readers click the text like [<text>](#ref), the web page will jump to the first position where <div id="ref"></div> is placed.

If we forget defining a division with a tag refff but we refer it using [<text>](#refff), there also won’t be errors when we click, and hyperlink will be changed as like:

image-20231031122550528

but the web page won’t jump to anywhere.

At this point, the HTML language is more tolerant than LaTeX typesetting system.


Markdown footnote identifier

Added on Nov. 4, 2023.

Fundamental usage from Markdown Guid [3]

Another way of cross reference is using Markdown identifier [3], i.e., creating a footnote reference by [^<footnote>], and adding footnote by [^<footnote>]:<footnote_content>. For example:

1
2
3
4
5
6
7
Here's [^2] a [^1] simple [^1] footnote,[^1] and here's a longer one.[^bignote]

[^1]: This is the first footnote.

[^bignote]: Here's one with multiple paragraphs and code.

[^2]: This is the second foot note.


Here’s 1 a 2 simple 2 footnote,2 and here’s a longer one.3


Markdown content will render output in .md file like this:

image-20231104140651912

If we click the blue mark which [^1] renders, markdown file will direct to where [^1]:This is the first footnote. defines; and similarly, if we click the orange carriage return symbol after [^1]:This is the first footnote., markdown file will return to where [^1] puts, and different orange carriage return symbols correspond to different [^1] identifiers. It is more efficient than using HTML <div> tag, cause the latter doesn’t function in .md file.

But the rendered appearance of markdown content is kind of different from that in .md file, reflecting in two aspects. Firstly, the detailed footnote contents will ALWAYS appear at the end of the page, no matter where they are put in .md file (It is reasonable, cause it is what “footnote” actually means). And the second one is that, the web page will re-name these footnotes using numbers, and re-organize them according to the occurrence order of [^<footnote>]. In a word, it is very similar to cross reference in LaTeX.

image-20231104160220867

image-20231104160332159

Besides, the website will automatically generate URL for each “footnote content”:

1
2
3
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fn:2
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fn:1
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fn:bignote

and for each “footnote”:

1
2
3
4
5
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fnref:2
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fnref:1
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fnref:1:1
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fnref:1:2
http://127.0.0.1:4000/2023-10-10/08-37-25.html#fnref:bignote

Anyway, I think it is a more convenient and efficient way to create a cross reference in Jekyll-based web page compared with using HTML <div> tag because it could produce more flexible redirections both in .md file and web page.

Formatting footnote style

Besides, we could format the footnote style using SCSS language. For the Jekyll theme “minimal-mistakes” 4 which I use, the footnote style is specified by the following codes in .\_sass\minimal-mistakes\_utilities.scss file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.footnote {
  color: mix(#fff, $gray, 25%);
  text-decoration: none;
}

.footnotes {
  color: mix(#fff, $gray, 25%);

  ol,
  li,
  p {
    margin-bottom: 0;
    font-size: $type-size-6;
  }
}

a.reversefootnote {
  color: $gray;
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }
}

I changed it to 5 6 7:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.footnote {
  color: #3366CC;
  text-decoration: none;
}
.footnote:before {
  content: "[";
}
.footnote:after {
  content: "]";
}

.footnotes {
  color: #3366CC;
  ol,
  li,
  p {
    margin-bottom: 0;
    font-size: 100%;
    text-decoration: none;
  }
}

a.reversefootnote {
  color: #FF0000;
  text-decoration: none;
  &:hover {
    text-decoration: underline;
  }
}

The new footnote style is like:

image-20231104191833536

image-20231104191802117


References

[1] Markdown 添加文献引用 - 别再闹了 - 博客园.

[2] HTML div tag - w3schools.

[3] Extended Syntax: Footnotes - Markdown Guide.

  1. This is the second foot note. ˄

  2. This is the first footnote. ˄ ˄2 ˄3

  3. Here’s one with multiple paragraphs and code. ˄

  4. mmistakes/minimal-mistakes- Github˄

  5. font-size - CSS: Cascading Style Sheets - MDN˄

  6. text-decoration - CSS: Cascading Style Sheets - MDN˄

  7. html - Square brackets with CSS - Stack Overflow˄