I have done this a bunch of times. Here’s an example adapted from how I did it in The Ascent of the Gothic Tower:
Hallway is a room.
The player is in Hallway.
The player carries the tome.
Nested Narrative Completed is initially false.
Instead of examining the tome:
if Nested Narrative Completed is false: [This sort of clause is useful if you don't want the player to be able to complicate things by playing your nested thingy over again, but it's not necessary.]
start the nested section;
otherwise:
say "You already read that tome. No need to go through all that again."
To start the nested section:
say "First there's some transitional text...[paragraph break][bracket]Press any key to continue...[close bracket][paragraph break]";
wait for any key;
now the story tense is past tense;
now the story viewpoint is first person singular;
now the player is Pat;
try looking.
Nested Story Area is a region.
Garden is a room in Nested Story Area.
Pat is a person in Garden.
It’s fun to change the story tense and/or story viewpoint for these nested narrative sections. In Gothic Tower it’s first person past tense because the nested story is a diary.
When you go back to the frame narrative, you have to restore the player to their initial “yourself” persona. And if you changed the story tense or viewpoint, you need to change those back. And if you’re using some variable to track something from the framed story, then, you’d better do that, too:
Instead of attacking the caelwyrm:
say "Without wasting another moment, I drove my spear into the caelwyrm's heart, thus undoing its curse. Here my story ends.[paragraph break][bracket]Press any key to continue...[close bracket][paragraph break]";
wait for any key;
now the player is yourself;
now the story viewpoint is second person singular;
now the story tense is present tense;
now Nested Narrative Completed is true;
try looking;
Now, in every project I start out with a bunch of custom default message replacements and little systems adjustments. I call this the “Boring” section. Below that, I start talking about the actual contents of the game, rooms and objects and stuff. Something like this:
"New Girl" by Ryan Veeder
Volume 1 - Boring
Instead of attacking something, say "You're not supposed to attack stuff in this game."
[And so on for smelling, squeezing, climbing...]
Volume 2 - Scenario
Loft is a room. Description of Loft is...
I organized the Gothic Tower source code by implementing everything in the main narrative first, and then implementing the framed section as basically its own little game.
Volume 1 - The Regular World
Book 1 - Boring stuff in the Regular World
Instead of attacking something:
say "You're not supposed to attack things in this part of the game."
Book 2 - Scenario of the Regular World
Hallway is a room.
Volume 2 - Nested Part
Nested Story Area is a region.
Book 1 - Boring stuff in Nested Part
Instead of attacking something while the location is in Nested Story Area:
say "I did not attack [the noun], for my sole charge was to rid this world of the hated caelwyrm."
Book 2 - Scenario in Nested Part
Garden is a room in Nested Story Area.
I probably copied the entire “Boring” section from the main part and added a “while the location is in…” to each rule before changing its text to match the tense/viewpoint/tone of the nested section.
The condition can be ...while the location is in {the region where you put all the rooms for the nested section}
or ...while the player is {the person you designate as the PC of the nested section}
or ...during {the scene that represents the nested section}
. (I never use scenes, so I can’t really speak to that.) The options are all equivalent… unless you do something complicated, like letting the protagonist of a book leap out into the real world.
So, for the “most simple” version of this idea, you don’t really need any fancy extensions. You basically just want to write an additional game for your nested story, and make sure that its rules only apply within that sub-game. And then you need rules for entering and leaving the story.
If the conditions on your rules are suitably specific, you can have as many sub-games as you want, nested any way you want, without all that much fuss.