Justin Does SICP

I started my second pass through SICP a few months after I had done the first (partial) pass. I found that looking at the material anew was good. I understood more the second time through.

And both times through, making an effort to explain something clearly helped me to see it more clearly myself.

Also, did you do anything in particular to get syntax highlighting working on your github site? thx

btw @AnneB i recommend this version of the book http://sarabander.github.io/sicp

1 Like

I think your q means for making posts via github pages, does one need to know more than markdown? If so:

You usually need to add some metadata (often it’s “yaml frontmatter”), but that’s just like author, date, etc. Besides that you don’t need to know anything more than markdown to make posts (at least using jekyll or hugo; two of the static site generators that github pages supports).

If you want to customize the template, or do more advanced stuff, then you need to know at least a bit about the relevant template language, html, and css.

You can see the code for Anne’s github pages site here: sicp-exercises/_config.yml at main · aelanteno/sicp-exercises · GitHub (well, this is actually the config file, but it shows you how simple it is). here’s a file with code that shows syntax highlighting (also mentioned below): https://raw.githubusercontent.com/aelanteno/sicp-exercises/main/exercise-1.10.md

From https://xertrov.github.io/fi, here’s an example of one of my posts (just plain markdown): fi/2020-09-02-analysing-lw-replies-for-social-dynamics.md at master · XertroV/fi · GitHub

You can hit the ‘raw’ button on the top right of the file to shown the plaintext version.

Most static site generators already support syntax highlighting when you use github flavored markdown with code fences, like this:

```scheme
(lambda (a x) (+ a x))
```
or (for python)
```python
x = 1
```

It seems to work on discorse, too. IDK about scheme but this is python:

def sum_some_ints(xs: List[int]) -> int:
  return 0 if len(xs) == 0 else xs[0] + sum_some_ints(xs[1:])

Though not every language is well supported on discorse – static site generators are usually better. e.g., haskell:

data TrafficLight = Green | Red | Yellow
  deriving (Eq)

canGo :: TrafficLight -> Boolean
canGo Green = True
canGo _ = False

Does this link take you to where you can see my github files?

I did use more than markdown for posting answers. Exercise 1.13 was complicated for me:

  • I wanted a nested outline with numbers on the first level and letters on the second level. I couldn’t figure out how to do that in markdown so I used html.
  • I also used html for superscripts, subscripts, and Greek letters.
  • For the bigger math formulas, I used a program called xFormula to make images, then used html to size them.

Syntax highlighting does work on github for scheme, the way Max showed, although I think it doesn’t always parse correctly. I didn’t like the default colors, so I changed them with this file, but you might be fine with them.

[edit to remove a strange formatting line that got put in when I quoted the post I was replying to]

FYI: It looks like you’re manually doing some of the maths notation. If you are, you might want to look into mathjax (relevant: https://medium.com/coffee-in-a-klein-bottle/creating-a-mathematics-blog-with-jekyll-78cdee0339f3).

Mathjax uses \LaTeX (latex; pronounced like “la-tek”) which the most commonly used typesetting language for maths stuff. (technically latex is one of a family of sorta-interchangable languages/engines based on \TeX (tex; pronounced “tek”); e.g., xetex and context are two others that come to mind.)

Mathjax works on discourse too, so I can show you:

inline you can put $F(\alpha) \approx \log_3(\sin(\theta))$ to render F(\alpha) \approx \log_3(\sin(\theta)).

you can do multi-line stuff like:

$$
f(x) = x^2 + 3x + 1 \\
\therefore \frac{d}{dx}f(x) = 2x + 3 \\
\therefore \frac{d^2}{dx^2}f(x) = 2 
$$
f(x) = x^2 + 3x + 1 \\ \therefore \frac{d}{dx}f(x) = 2x + 3 \\ \therefore \frac{d^2}{dx^2}f(x) = 2
$$
S = \sum_{i=1}^n ar^i
$$
S = \sum_{i=1}^n ar^i
1 Like

Hmm. Looking at that post you linked to… I didn’t install Jekyll and GitHub Pages, I just used them. I don’t know anything about Ruby. I’m not sure where I’d type the lines of code they show. BUT I would like to try to get MathJax to work someday. I’ll put it on my list of things to work on in the future. I’m not going to do it now because I want to finish The Little Schemer before going back to my SICP stuff. Thank you.

You don’t have to install jekyll locally – that just helps with testing stuff b/c it’s a quicker cycle-time (don’t have to wait for github pages to update).

When you want to look into mathjax, skip to this part of the article:

Basically this is all you need to do to get mathjax working:

Most of the article isn’t about mathjax itself.

edit: PS: yw

1 Like

Oh, that looks easy!

1 Like

I tried the method on the page Max linked but didn’t get Github to display Latex

However, I put

  <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>

within a /_layouts/default.html file that i basically copied from Anne’s repository and that worked. I was also able to dump that script into my Ghost blog’s code injection thing and have mathjax work on that too :slight_smile:

1 Like

@AnneB is it intentional that https://aelanteno.github.io/ has no content?
and is it easy to organize hosting multiple projects on a Github pages site?

the Github Pages stuff was a bit more setup than I thought it would be.

Not intentional. I didn’t realize that was a place. I should put something there. Thank you.

I haven’t tried, but it seems like it is.

Github pages are usually hosted at <username>.github.io/<repo_name>. You can host things at the root directory, though. From Creating a GitHub Pages site with Jekyll:

Type a name for your repository and an optional description. If you’re creating a user or organization site, your repository must be named <user>.github.io or <organization>.github.io . For more information, see “About GitHub Pages.”

From About GitHub Pages:

To publish a user site, you must create a repository owned by your user account that’s named <username>.github.io . To publish an organization site, you must create a repository owned by an organization that’s named <organization>.github.io . Unless you’re using a custom domain, user and organization sites are available at http(s)://<username>.github.io or http(s)://<organization>.github.io .

Here’s a super simple way to put something at the root, using Anne’s GH account as an example:

  1. create a repo called aelanteno.github.io
  2. create a file in the root of this repo called index.html with the contents below
  3. (optional) enable github pages for that repo – when I tried this method just now I didn’t need to enable it, that happened automatically.

index.html contents:

<html>
<head>
<meta http-equiv="Refresh" content="0; url='/sicp-exercises/'" />
</head>
<body>Redirecting...</body>
</html>

Here’s my repo where I did this for https://xertrov.github.io/ so it redirects to https://xertrov.github.io/fi: https://github.com/XertroV/xertrov.github.io

Addendum re J’s quote:

I can think of 2 ways to do this:

You can host multiple github pages websites in diff repositories and they’ll show up via the <username>.github.io/<repo_name> url. If you do that: each repo is a different github pages site, so you can use different themes, or diff site generators, or whatever.

You can also create pretty complex sites from just one repo. My FI GH pages site is like that. The repo has more than just the static site in it (the site is under /docs), and you can see I have lots of collections (which are the folders in that directory that start with an underscore). Here’s the config for those collections to make them have specific URLs. (Note: “collections” are a Jekyll thing. You can do similar stuff with Hugo and other site generators, but IDK what terminology those other generators use)

oh. guide i read said make repo name the username.github.io thing by itself

Yes, if you want to host something at the root of <username>.github.io. The quotes I have from github pages docs call this a “user site” (or “organization site”). I realized (rereading now) that probably wasn’t obvious.

OH. lol, yeah that sure wasn’t obvious. i thought maybe you were supposed to host at the root. i didn’t realize github pages was just a flip you could switch on any old repository. the material i came across didn’t adequately explain this.

I did this and now it the root redirects to my repo :smiley:
thx Max!

1 Like

8 posts were split to a new topic: Resizing images in Ghost/Ulysses